import Vue from 'vue' import App from './App' import store from '@/store/store.js'; import { php, go } from '@/common/host.js'; import { getNavigationBarTitle, getCache } from './common/util.js'; // 微信分享公共接口 // #ifdef H5 import wechat from './common/wechat.js'; Vue.prototype.$wechat = wechat; // if (wechat.isWechat() || wechat.isMini()) { // Vue.prototype.$wechat = wechat; // } // #endif Vue.config.productionTip = false; // 加入购物车 function addCart(spec_id, quantity, isLogin) { if (!isLogin) { uni.showToast({ title: '请登录后加入购物车', duration: 2000, icon: 'none' }); setTimeout(() => { window.location.href = php + 'app=member&act=login'; }, 2000); return } uni.request({ url: '/uni/api//credit_goods/add_cart', method: 'post', dataType: 'json', data: { spec_id: spec_id, quantity: quantity }, success: (res) => { let msg = ''; if (res.data.code == 0) { msg = '已加入购物车' } else { msg = res.data.messages } uni.showToast({ title: msg, duration: 2000, icon: 'none' }); } }) } // 默认图片加载失败的情况 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'; } // 毫秒数转时间 // 跳转商品详情页,只传一个商品ID,方便以后全局修改 function jumpGoodDetail(goods_id) { window.location.href = `${php}app=goods&id=${goods_id}`; } function jumpOrderDetail(order_id) { window.location.href = `${php}app=buyer_order&act=view&order_id=${order_id}`; } function backup() { const routes = getCurrentPages(); if (routes.length > 1) { uni.navigateBack(); } else { history.back(); } } // 跳转外部链接,使用webview function jump(url, type) { // #ifdef H5 if(type === 1){ // 重定向到指定地址,防止回退 window.location.replace(url); } else if (type === 2){ uni.navigateTo({ url: url }) } else { 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; Vue.prototype.$jumpOrderDetail = jumpOrderDetail; Vue.prototype.$getCache = getCache; Vue.prototype.$addCart = addCart; Vue.prototype.$backup = backup; 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'; 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'; App.mpType = 'app' const app = new Vue({ ...App, store }) app.$mount()