封装函数

This commit is contained in:
yanran200730
2023-08-08 11:08:09 +08:00
parent aea8585182
commit 3b1de45fbf
4 changed files with 74 additions and 42 deletions

View File

@@ -50,10 +50,13 @@ export default new Vuex.Store({
actions: {
getUserInfo (store) {
request.post('/api/malluser/info').then(res => {
if (res.code === 0) {
store.commit('setUserInfo', res.data)
}
return new Promise(resolve => {
request.post('/api/malluser/info').then(res => {
if (res.code === 0) {
store.commit('setUserInfo', res.data)
resolve(res.data)
}
})
})
}
},

View File

@@ -1,4 +1,6 @@
import request from '../api'
import store from '../store'
import { Message } from 'element-ui'
const dict = {
url: "/dictionary/queryValsByCodeList",
@@ -88,9 +90,30 @@ const dateUtil = {
}
}
const userCheck = () => {
store.dispatch('getUserInfo').then(res => {
return new Promise((resolve, reject) => {
if (res.data.flag != 1) {
Message.error('您的账号未激活或已失效,请激活后使用')
this.$store.commit('setActiveDlgShow', true)
reject('您的账号未激活或已失效,请激活后使用')
return false
}
if (res.data.type != 4 && this.$store.state.mallId != this.$store.state.userInfo.mallId) {
Message.error('您当前登录的TEMU账号与会员绑定账号不一致')
reject('您当前登录的TEMU账号与会员绑定账号不一致')
return false
}
resolve(res.data)
})
})
}
export default {
dict,
dateUtil,
userCheck
}

View File

@@ -61,6 +61,9 @@
},
created () {
this.$store.dispatch('getUserInfo').then(e => {
console.log(e)
})
this.getCateList()
this.getList()
},
@@ -89,7 +92,6 @@
},
collection (id, isFavorite) {
console.log(isFavorite)
this.$confirm(isFavorite === '0' ? '确定收藏该文章?' : '确定取消收藏?', '温馨提示', {
confirmButtonText: '确定',
callback: action => {

View File

@@ -279,46 +279,50 @@
}
return;
}
this.$http.post('/api/malluser/info').then(res => {
if (res.code == 0) {
this.$store.commit('setUserInfo', res.data)
if (res.data.flag != 1) {
Message.error('您的账号未激活或已失效,请激活后使用')
this.$store.commit('setActiveDlgShow', true)
return;
}
if (res.data.type != 4 && this.$store.state.mallId != this.$store.state.userInfo.mallId) {
Message.error('您当前登录的TEMU账号与会员绑定账号不一致')
return;
}
if (this.choosedList.length <= 0) {
Message.error('请选择备货单');
return;
}
this.robTotal = this.choosedList.length
this.isBegin = true;
this.timer = [];
for (let i = 0;i < this.choosedList.length; i++) {
setTimeout(() => {
let t = setInterval(this.robFunc(this.choosedList[i].subPurchaseOrderSn, this.choosedList[i].mallId), 1000);
this.timer.push({id: this.choosedList[i].subPurchaseOrderSn, timer: t})
}, 100 * i)
}
let _this = this;
let tt = setInterval(function() {
if (_this.choosedList.length == 0) {
_this.isBegin = false;
clearInterval(tt);
}
}, 1000)
} else {
console.log("获取用户信息失败")
this.$userCheck.then(() => {
if (this.choosedList.length <= 0) {
Message.error('请选择备货单');
return;
}
});
this.robTotal = this.choosedList.length
this.isBegin = true;
this.timer = [];
for (let i = 0;i < this.choosedList.length; i++) {
setTimeout(() => {
let t = setInterval(this.robFunc(this.choosedList[i].subPurchaseOrderSn, this.choosedList[i].mallId), 1000);
this.timer.push({id: this.choosedList[i].subPurchaseOrderSn, timer: t})
}, 100 * i)
}
let _this = this;
let tt = setInterval(function() {
if (_this.choosedList.length == 0) {
_this.isBegin = false;
clearInterval(tt);
}
}, 1000)
}).catch((err) => {
console.log(err)
})
// this.$http.post('/api/malluser/info').then(res => {
// if (res.code == 0) {
// this.$store.commit('setUserInfo', res.data)
// if (res.data.flag != 1) {
// Message.error('您的账号未激活或已失效,请激活后使用')
// this.$store.commit('setActiveDlgShow', true)
// return;
// }
// if (res.data.type != 4 && this.$store.state.mallId != this.$store.state.userInfo.mallId) {
// Message.error('您当前登录的TEMU账号与会员绑定账号不一致')
// return;
// }
// } else {
// console.log("获取用户信息失败")
// }
// });
},
robFunc(sn, mallId) {
let _this = this;