增加基本项目配置
This commit is contained in:
51
libs/chat.js
Normal file
51
libs/chat.js
Normal file
@ -0,0 +1,51 @@
|
||||
import $store from "@//store";
|
||||
import { VUE_APP_WS_URL } from "@/utils";
|
||||
|
||||
const Socket = function() {
|
||||
this.ws = new WebSocket(VUE_APP_WS_URL);
|
||||
this.ws.onopen = this.onOpen.bind(this);
|
||||
this.ws.onerror = this.onError.bind(this);
|
||||
this.ws.onmessage = this.onMessage.bind(this);
|
||||
this.ws.onclose = this.onClose.bind(this);
|
||||
};
|
||||
|
||||
Socket.prototype = {
|
||||
vm(vm) {
|
||||
this.vm = vm;
|
||||
},
|
||||
close() {
|
||||
clearInterval(this.timer);
|
||||
this.ws.close();
|
||||
},
|
||||
onOpen: function() {
|
||||
this.init();
|
||||
this.send({
|
||||
type: "login",
|
||||
data: $store.state.token
|
||||
});
|
||||
this.vm.$emit("socket_open");
|
||||
},
|
||||
init: function() {
|
||||
var that = this;
|
||||
this.timer = setInterval(function() {
|
||||
that.send({ type: "ping" });
|
||||
}, 10000);
|
||||
},
|
||||
send: function(data) {
|
||||
return this.ws.send(JSON.stringify(data));
|
||||
},
|
||||
onMessage: function(res) {
|
||||
const { type, data = {} } = JSON.parse(res.data);
|
||||
this.vm.$emit(type, data);
|
||||
},
|
||||
onClose: function() {
|
||||
clearInterval(this.timer);
|
||||
},
|
||||
onError: function(e) {
|
||||
this.vm.$emit("socket_error", e);
|
||||
}
|
||||
};
|
||||
|
||||
Socket.prototype.constructor = Socket;
|
||||
|
||||
export default Socket;
|
32
libs/login.js
Normal file
32
libs/login.js
Normal file
@ -0,0 +1,32 @@
|
||||
// import router from "../router";
|
||||
import store from "../store";
|
||||
import cookie from "@/utils/store/cookie";
|
||||
import { isWeixin, login, getCurrentPageUrl, getCurrentPageUrlWithArgs, parseQuery, replace, handleQrCode } from "@/utils";
|
||||
|
||||
export default function toLogin(push, backUrl) {
|
||||
store.commit("LOGOUT");
|
||||
if (store.getters.isAuthorization) {
|
||||
login()
|
||||
return
|
||||
}
|
||||
if (store.getters.isAuthorizationPage || getCurrentPageUrl() == '/pages/user/Login/index') {
|
||||
return
|
||||
}
|
||||
|
||||
// 判断是不是扫描的砍价海报进来的
|
||||
if (getCurrentPageUrl() == 'pages/activity/DargainDetails/index' && handleQrCode()) {
|
||||
let url = handleQrCode();
|
||||
if (url) {
|
||||
console.log(222222222)
|
||||
replace({ path: '/pages/user/Login/index', query: { redirect: `/${getCurrentPageUrl()}`, id: url.bargainId, partake: url.uid } })
|
||||
} else {
|
||||
replace({ path: '/pages/user/Login/index', query: { redirect: `/${getCurrentPageUrl()}`, ...parseQuery() } })
|
||||
}
|
||||
} else {
|
||||
console.log(222222222)
|
||||
replace({ path: '/pages/user/Login/index', query: { redirect: `/${getCurrentPageUrl()}`, ...parseQuery() } })
|
||||
}
|
||||
store.commit("UPDATE_AUTHORIZATION", false);
|
||||
store.commit("UPDATE_AUTHORIZATIONPAGE", true);
|
||||
}
|
||||
|
107
libs/order.js
Normal file
107
libs/order.js
Normal file
@ -0,0 +1,107 @@
|
||||
import { cancelOrder, takeOrder, delOrder, payOrder } from "@/api/order";
|
||||
import dialog from "@/utils/dialog";
|
||||
import { weappPay } from "@/libs/wechat";
|
||||
|
||||
export function cancelOrderHandle(orderId) {
|
||||
return new Promise((resolve, reject) => {
|
||||
wx.showModal({
|
||||
title: '提示',
|
||||
content: '确认取消该订单?',
|
||||
success(res) {
|
||||
if (res.confirm) {
|
||||
cancelOrder(orderId)
|
||||
.then(res => {
|
||||
wx.showToast({
|
||||
title: '取消成功', icon: 'success', duration: 2000
|
||||
});
|
||||
resolve(res);
|
||||
})
|
||||
.catch(err => {
|
||||
wx.showToast({
|
||||
title: '取消失败', icon: 'none', duration: 2000
|
||||
});
|
||||
reject(err);
|
||||
});
|
||||
} else if (res.cancel) {
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
export function takeOrderHandle(orderId) {
|
||||
return new Promise((resolve, reject) => {
|
||||
takeOrder(orderId)
|
||||
.then(res => {
|
||||
wx.showToast({
|
||||
title: '收货成功', icon: 'success', duration: 2000
|
||||
});
|
||||
resolve(res);
|
||||
})
|
||||
.catch(err => {
|
||||
wx.showToast({
|
||||
title: '收货失败', icon: 'none', duration: 2000
|
||||
});
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function delOrderHandle(orderId) {
|
||||
return new Promise((resolve, reject) => {
|
||||
dialog.confirm({
|
||||
mes: "确认删除该订单?",
|
||||
opts() {
|
||||
delOrder(orderId)
|
||||
.then(res => {
|
||||
wx.showToast({
|
||||
title: '删除成功', icon: 'success', duration: 2000
|
||||
});
|
||||
resolve(res);
|
||||
})
|
||||
.catch(err => {
|
||||
wx.showToast({
|
||||
title: '删除失败', icon: 'none', duration: 2000
|
||||
});
|
||||
reject(err);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function payOrderHandle(orderId, type, from) {
|
||||
return new Promise((resolve, reject) => {
|
||||
wx.showLoading({ title: '加载中' })
|
||||
payOrder(orderId, type, from)
|
||||
.then(res => {
|
||||
const data = res.data;
|
||||
wx.hideLoading()
|
||||
switch (data.status) {
|
||||
case "WECHAT_H5_PAY":
|
||||
location.replace(data.result.jsConfig.mweb_url);
|
||||
reject(data);
|
||||
break;
|
||||
case "ORDER_EXIST":
|
||||
case "EXTEND_ORDER":
|
||||
case "PAY_ERROR":
|
||||
case "PAY_DEFICIENCY":
|
||||
dialog.toast({ mes: res.msg });
|
||||
reject(data);
|
||||
break;
|
||||
case "SUCCESS":
|
||||
wx.showToast({ title: res.msg, icon: 'none', duration: 2000 });
|
||||
resolve(data);
|
||||
break;
|
||||
case "WECHAT_PAY":
|
||||
weappPay(data.result.jsConfig).then(res => {
|
||||
resolve(data);
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
wx.hideLoading()
|
||||
dialog.toast({ mes: "订单支付失败" });
|
||||
});
|
||||
});
|
||||
}
|
20
libs/wechat.js
Normal file
20
libs/wechat.js
Normal file
@ -0,0 +1,20 @@
|
||||
// 支付模块
|
||||
export const weappPay = (option) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
// 吊起微信支付
|
||||
wx.requestPayment({
|
||||
...option,
|
||||
timeStamp: option.timeStamp + '',
|
||||
success: (success) => {
|
||||
wx.showToast({
|
||||
title: '支付成功', icon: 'success', duration: 2000
|
||||
});
|
||||
resolve(success)
|
||||
},
|
||||
fail: (error) => {
|
||||
wx.showToast({ title: '支付失败', icon: 'none', duration: 2000 });
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user