main.js 2.45 KB
Newer Older
1
import Vue from 'vue'
王建威's avatar
王建威 committed
2
import App from './App'
王建威's avatar
王建威 committed
3
import store from './store/store.js';
4
import { php, gp } from './common/host.js';
5 6 7 8 9 10 11 12
import { getNavigationBarTitle } from './common/util.js';

// 微信分享公共接口
// #ifdef H5  
import wechat from './common/wechat.js';
if(wechat.isWechat()){
  Vue.prototype.$wechat = wechat;
}
13 14
// #endif

15
Vue.config.productionTip = false;
王建威's avatar
王建威 committed
16 17

// 加入购物车
王建威's avatar
王建威 committed
18
function addCart(spec_id, quantity, isLogin) {
王建威's avatar
王建威 committed
19 20
	if(!isLogin) {
		uni.showToast({
21
		    title: '请登录后加入购物车',
王建威's avatar
王建威 committed
22 23 24 25
		    duration: 2000,
			icon: 'none'
		});
		setTimeout(() => {
王建威's avatar
王建威 committed
26
			window.location.href = php+'app=member&act=login';
王建威's avatar
王建威 committed
27 28 29
		}, 2000);
		return
	}
王建威's avatar
王建威 committed
30 31 32 33 34 35 36 37 38
	uni.request({
		url: '/uni/api//credit_goods/add_cart',
		method: 'post',
		dataType: 'json',
		data: {
			spec_id: spec_id,
			quantity: quantity
		},
		success: (res) => {
王建威's avatar
王建威 committed
39 40 41 42 43 44 45 46 47 48 49
			let msg = '';
			if(res.data.code == 0) {
				msg = '已加入购物车'
			} else {
				msg = res.data.messages
			}
			uni.showToast({
			    title: msg,
			    duration: 2000,
				icon: 'none'
			});
王建威's avatar
王建威 committed
50 51
		}
	})
王建威's avatar
王建威 committed
52
}
53 54 55
// 默认图片加载失败的情况
function __reloadResource(_this){
	_this._source.default_image = 'https://dbc-static.oss-cn-beijing.aliyuncs.com/credit_shop/20190605/goods/5cf78b96601be.png?x-oss-process=image/resize,m_lfit,w_300,h_300/auto-orient,0/quality,Q_85/format,jpg';
56
}
王建威's avatar
王建威 committed
57

王建威's avatar
王建威 committed
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
// 跳转商品详情页,只传一个商品ID,方便以后全局修改

function jumpGoodDetail(goods_id) {
	window.location.href = `${php}app=goods&id=${goods_id}`;
}

// 跳转外部链接,使用webview
function jump(url) {
	// #ifdef H5
	window.location.href = url;
	// #endif
	
	// #ifndef H5
	const link = url
	store.dispatch('changeWebviewUrl',link)
	uni.redirectTo({
		url: `/pages/web/web`,
	});
	// #endif
}

Vue.prototype.$jumpGoodDetail = jumpGoodDetail;
Vue.prototype.$jump = jump;
王建威's avatar
王建威 committed
81
Vue.prototype.$addCart = addCart;
82 83 84
Vue.prototype.$__reloadResource = __reloadResource;
Vue.prototype.$getNavigationBarTitle = getNavigationBarTitle;
Vue.prototype.$noGoodsImg = 'https://dbc-static.oss-cn-beijing.aliyuncs.com/credit_shop/20190605/goods/5cf78b96601be.png?x-oss-process=image/resize,m_lfit,w_300,h_300/auto-orient,0/quality,Q_85/format,jpg';
王建威's avatar
王建威 committed
85 86
Vue.prototype.$defaultPortrait = 'https://dbc-static.oss-cn-beijing.aliyuncs.com/credit/default_user_portrait.gif';
Vue.prototype.$defaultClassImg = 'https://dbc-static.oss-cn-beijing.aliyuncs.com/credit_shop/20190520/img/5ce2636edf912.png';
87 88 89 90

App.mpType = 'app'

const app = new Vue({
王建威's avatar
王建威 committed
91
    ...App,
92 93
	store
})
郑秀明's avatar
郑秀明 committed
94
app.$mount()