301 lines
7.0 KiB
JavaScript
Executable File
301 lines
7.0 KiB
JavaScript
Executable File
import Vue from 'vue'
|
|
import Vuex from 'vuex'
|
|
// import {request} from '../common/j-request/index.js'
|
|
import errorUtil from '../common/errorutil.js';
|
|
|
|
Vue.use(Vuex)
|
|
|
|
const store = new Vuex.Store({
|
|
state: {
|
|
hasLogin: false,
|
|
userInfo:{},
|
|
UserName:'',
|
|
Phone:'',
|
|
//loginProvider: "",
|
|
openid: null,
|
|
hasConnect:false,
|
|
dbInfo:{},
|
|
//部门
|
|
deptInfos: null,
|
|
//客户
|
|
customerInfos: null,
|
|
//供应商
|
|
supplierInfos: null,
|
|
//源单类型
|
|
billTypeInfos: null,
|
|
//系统配置
|
|
sysParameters: null
|
|
},
|
|
|
|
mutations: {
|
|
login(state, provider) {
|
|
state.hasLogin = true;
|
|
//state.loginProvider = provider;
|
|
//state.userInfo.token=provider.token;
|
|
state.UserName=provider.UserName;
|
|
state.Phone=provider.phone;
|
|
state.userInfo=provider;
|
|
uni.setStorage({
|
|
key:'userInfo',
|
|
data:provider
|
|
});
|
|
|
|
},
|
|
|
|
logout(state) {
|
|
state.hasLogin = false
|
|
state.openid = null
|
|
state.userInfo={}
|
|
uni.removeStorage({
|
|
key:'userInfo'
|
|
});
|
|
/*uni.removeStorage({
|
|
key:'Avatar'
|
|
});*/
|
|
},
|
|
|
|
setOpenid(state, openid) {
|
|
state.openid = openid
|
|
},
|
|
|
|
connectDB(state, provider){
|
|
state.hasConnect = true;
|
|
state.dbInfo=provider;
|
|
uni.setStorage({
|
|
key:'dbInfo',
|
|
data:provider
|
|
})
|
|
},
|
|
|
|
cutConnect(state){
|
|
state.hasConnect = false
|
|
state.dbInfo={}
|
|
uni.removeStorage({
|
|
key:'dbInfo'
|
|
});
|
|
},
|
|
|
|
clearCache(state){
|
|
uni.clearStorage();
|
|
state.hasLogin = false;
|
|
state.userInfo = null;
|
|
state.UserName = null;
|
|
state.Phone = null;
|
|
state.openid = null;
|
|
state.hasConnect = false;
|
|
state.dbInfo = null;
|
|
|
|
state.deptInfos = null;
|
|
state.customerInfos = null;
|
|
state.supplierInfos = null;
|
|
state.billTypeInfos = null;
|
|
state.sysParameters = null;
|
|
console.log("----系统缓存清除-----");
|
|
},
|
|
|
|
//部门
|
|
saveDeptInfos(state, provider) {
|
|
state.deptInfos = provider;
|
|
|
|
uni.setStorage({
|
|
key: 'deptInfos',
|
|
data: provider,
|
|
success: function () {
|
|
console.log('deptInfos success');
|
|
}
|
|
});
|
|
},
|
|
|
|
//客户
|
|
saveCustomerInfos(state, provider) {
|
|
state.customerInfos = provider;
|
|
|
|
uni.setStorage({
|
|
key: 'customerInfos',
|
|
data: provider,
|
|
success: function () {
|
|
console.log('customerInfos success');
|
|
}
|
|
});
|
|
},
|
|
|
|
//供应商
|
|
saveSupplierInfos(state, provider) {
|
|
state.supplierInfos = provider;
|
|
|
|
uni.setStorage({
|
|
key: 'supplierInfos',
|
|
data: provider,
|
|
success: function () {
|
|
console.log('supplierInfos success');
|
|
}
|
|
});
|
|
},
|
|
|
|
//源单类型
|
|
saveBillTypeInfos(state, provider) {
|
|
let src = new Object();
|
|
if(state.billTypeInfos) {
|
|
Object.assign(src, state.billTypeInfos);
|
|
// let des = Object.getOwnPropertyDescriptors(state.billTypeInfos);
|
|
// // 通过对象属性描述创建新对象
|
|
// Object.defineProperties(src, des);
|
|
}
|
|
|
|
Object.defineProperty(src, provider["key"], {
|
|
value: provider["value"],
|
|
writable: true,
|
|
configurable:true,
|
|
enumerable:true
|
|
});
|
|
|
|
state.billTypeInfos = src;
|
|
|
|
uni.setStorage({
|
|
key: "billTypeInfos",
|
|
data: state.billTypeInfos,
|
|
success: function () {
|
|
console.log('billTypeInfos success');
|
|
}
|
|
});
|
|
},
|
|
|
|
//系统参数
|
|
saveSysParameters(state, provider) {
|
|
if(!state.sysParameters) {
|
|
state.sysParameters = new Object();
|
|
}
|
|
|
|
Object.defineProperty(state.sysParameters, provider["key"], {
|
|
value: provider["value"],
|
|
writable: true,
|
|
configurable:true,
|
|
enumerable:true
|
|
});
|
|
|
|
uni.setStorage({
|
|
key: "sysParameters",
|
|
data: state.sysParameters,
|
|
success: function () {
|
|
console.log('sysParameters success' + state.sysParameters);
|
|
}
|
|
});
|
|
},
|
|
|
|
updateCacheByStorage(state) {
|
|
// console.log("----updateCacheByStorage----" );
|
|
|
|
// uni.getStorage({
|
|
// key: 'sysParameters',
|
|
// success: function (res) {
|
|
// state.sysParameters = res.data;
|
|
// console.log("----updateCacheByStorage sysParameters----" + state.sysParameters);
|
|
// }
|
|
// });
|
|
|
|
// uni.getStorage({
|
|
// key: 'billTypeInfos',
|
|
// success: function (res) {
|
|
// state.billTypeInfos = res.data;
|
|
// console.log("----updateCacheByStorage billTypeInfos----" + state.billTypeInfos);
|
|
// }
|
|
// });
|
|
|
|
// uni.getStorage({
|
|
// key: 'supplierInfos',
|
|
// success: function (res) {
|
|
// state.supplierInfos = res.data;
|
|
// console.log("----updateCacheByStorage supplierInfos----" + state.supplierInfos);
|
|
// }
|
|
// });
|
|
|
|
// uni.getStorage({
|
|
// key: 'customerInfos',
|
|
// success: function (res) {
|
|
// state.customerInfos = res.data;
|
|
// console.log("----updateCacheByStorage customerInfos----" + state.customerInfos);
|
|
// }
|
|
// });
|
|
|
|
|
|
// uni.getStorage({
|
|
// key: 'deptInfos',
|
|
// success: function (res) {
|
|
// state.deptInfos = res.data;
|
|
// console.log("----updateCacheByStorage deptInfos----" + state.deptInfos);
|
|
// }
|
|
// });
|
|
|
|
}
|
|
},
|
|
|
|
actions: {
|
|
// lazy loading openid
|
|
getUserOpenId: async function ({
|
|
commit,
|
|
state
|
|
}) {
|
|
return await new Promise((resolve, reject) => {
|
|
if (state.openid) {
|
|
resolve(state.openid)
|
|
} else {
|
|
uni.login({
|
|
success: (data) => {
|
|
commit('login')
|
|
setTimeout(function () { //模拟异步请求服务器获取 openid
|
|
const openid = '123456789'
|
|
console.log('uni.request mock openid[' + openid + ']');
|
|
commit('setOpenid', openid)
|
|
resolve(openid)
|
|
}, 1000)
|
|
},
|
|
fail: (err) => {
|
|
console.log('uni.login 接口调用失败,将无法正常使用开放接口等服务', err)
|
|
reject(err)
|
|
}
|
|
})
|
|
}
|
|
})
|
|
},
|
|
|
|
getBillTypeInfos: async function ({commit, state}, provider) {
|
|
let cachekey = provider.tranType;
|
|
let tranType = provider.tranType;
|
|
let userID = provider.userID;
|
|
|
|
return await new Promise((resolve, reject) => {
|
|
let updateFlag = !state.billTypeInfos;
|
|
|
|
if(!updateFlag) {
|
|
if(!state.billTypeInfos.hasOwnProperty(tranType)) {
|
|
updateFlag = true;
|
|
}
|
|
}
|
|
|
|
if(updateFlag) {
|
|
request.post({
|
|
data: {
|
|
action: 'QuerySelBill',
|
|
params: {
|
|
"id": userID,
|
|
"tranType": tranType
|
|
},
|
|
}
|
|
}).then(res => {
|
|
console.log("----getBillTypeInfos---- requestsuccess" + res);
|
|
let data = JSON.parse(res);
|
|
commit('saveBillTypeInfos', {value:data, key:cachekey});
|
|
resolve("success");
|
|
}).catch(err => {
|
|
errorUtil.handle(err);
|
|
// console.log("----getBillTypeInfos---- requestfail");
|
|
// reject("请求失败,请检查网络设置");
|
|
});
|
|
}
|
|
});
|
|
|
|
}
|
|
}
|
|
})
|
|
|
|
export default store |