project init
This commit is contained in:
72
store/models/area.js
Normal file
72
store/models/area.js
Normal file
@@ -0,0 +1,72 @@
|
||||
import areaData from '@/untils/area';
|
||||
|
||||
function format(data) {
|
||||
const result = [];
|
||||
const children = {};
|
||||
const dic = {
|
||||
'0': {
|
||||
label: 'root',
|
||||
value: '0',
|
||||
children: result
|
||||
}
|
||||
};
|
||||
|
||||
data.forEach(item => {
|
||||
if (item.layer > 3) {
|
||||
return;
|
||||
}
|
||||
const node = {
|
||||
label: item.areaName,
|
||||
value: item.areaId,
|
||||
quickQuery: item.quickQuery,
|
||||
simpleSpelling: item.simpleSpelling,
|
||||
parentId: item.parentId
|
||||
};
|
||||
if (children.hasOwnProperty(item.parentId)) {
|
||||
children[item.parentId].push(node);
|
||||
} else {
|
||||
children[item.parentId] = [node];
|
||||
}
|
||||
if (dic.hasOwnProperty(item.areaId)) {
|
||||
dic[item.areaId].label = item.areaName;
|
||||
dic[item.areaId].value = item.areaId;
|
||||
} else {
|
||||
dic[item.areaId] = node;
|
||||
}
|
||||
});
|
||||
return {
|
||||
data: result,
|
||||
children,
|
||||
dic
|
||||
};
|
||||
}
|
||||
|
||||
let loaded = false
|
||||
|
||||
const data = format(areaData)
|
||||
const area = {
|
||||
state: {
|
||||
...data
|
||||
},
|
||||
actions: {},
|
||||
mutations: {
|
||||
SET_AREA: (state, data) => {
|
||||
state.data = data.data
|
||||
state.dic = data.dic
|
||||
},
|
||||
},
|
||||
getters: {
|
||||
getAreaParents: (state) => (id) => {
|
||||
const res = [];
|
||||
let item = state.dic[id];
|
||||
while (item && item.value !== '0') {
|
||||
id = item.parentId;
|
||||
res.unshift(item);
|
||||
item = state.dic[id];
|
||||
}
|
||||
return res
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default area;
|
||||
167
store/models/auth.js
Normal file
167
store/models/auth.js
Normal file
@@ -0,0 +1,167 @@
|
||||
import {
|
||||
findAuth,
|
||||
cheakValue,
|
||||
insure
|
||||
} from '@/api/auth.js'
|
||||
import {
|
||||
getStore,
|
||||
setStore
|
||||
} from '@/untils/store.js'
|
||||
import {
|
||||
realName
|
||||
} from '@/api/auth.js'
|
||||
|
||||
const convert = (v) => {
|
||||
return v === '1'
|
||||
}
|
||||
|
||||
const auth = {
|
||||
state: {
|
||||
laborState: getStore({
|
||||
name: 'laborState'
|
||||
}) || false,
|
||||
realNameState: getStore({
|
||||
name: 'realNameState'
|
||||
}) || false,
|
||||
bankCardState: getStore({
|
||||
name: 'bankCardState'
|
||||
}) || false,
|
||||
insureState: getStore({
|
||||
name: 'insureState'
|
||||
}) || false,
|
||||
authInfo: getStore({
|
||||
name: 'authInfo'
|
||||
}) || []
|
||||
},
|
||||
actions: {
|
||||
//刷新token
|
||||
refreshAuthState({
|
||||
commit,
|
||||
dispatch
|
||||
}) {
|
||||
// authValue 身份信息|实名认证|银行卡认证|社保信息
|
||||
return new Promise((resolve, reject) => {
|
||||
findAuth().then((res) => {
|
||||
const data = res.data.data;
|
||||
const authValue = data.authValue
|
||||
|
||||
commit('SET_AUTH_LABOR', convert(authValue[0]))
|
||||
commit('SET_AUTH_REALNAME', convert(authValue[1]))
|
||||
commit('SET_AUTH_BANKCARD', convert(authValue[2]))
|
||||
commit('SET_AUTH_INSURE', convert(authValue[3]))
|
||||
commit('SET_AUTH_INFO', data)
|
||||
dispatch('getVipCode')
|
||||
|
||||
resolve()
|
||||
}).catch(reject)
|
||||
})
|
||||
},
|
||||
authRealName({
|
||||
commit,
|
||||
dispatch
|
||||
}, {
|
||||
name,
|
||||
idNumber
|
||||
}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
realName(name, idNumber).then(() => {
|
||||
commit('SET_AUTH_REALNAME', true)
|
||||
commit('UPDATE_AUTH_REALNAME', {
|
||||
realName: name,
|
||||
idNumber: idNumber
|
||||
})
|
||||
dispatch('getVipCode')
|
||||
resolve()
|
||||
}).catch(reject)
|
||||
})
|
||||
},
|
||||
authLabor({
|
||||
commit,
|
||||
dispatch
|
||||
}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
cheakValue(1).then(resp => {
|
||||
commit('SET_AUTH_LABOR', true)
|
||||
resolve()
|
||||
}).catch(reject)
|
||||
})
|
||||
},
|
||||
authInsure({
|
||||
commit,
|
||||
dispatch
|
||||
}, data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
insure(data).then(resp => {
|
||||
commit('SET_AUTH_INSURE', true)
|
||||
commit('UPDATE_AUTH_INSURE_TYPE', data)
|
||||
resolve()
|
||||
}).catch(reject)
|
||||
})
|
||||
},
|
||||
clearAuthState({
|
||||
commit
|
||||
}) {
|
||||
commit('SET_AUTH_LABOR', '')
|
||||
commit('SET_AUTH_REALNAME', '')
|
||||
commit('SET_AUTH_BANKCARD', '')
|
||||
commit('SET_AUTH_INSURE', '')
|
||||
commit('SET_AUTH_INFO', '')
|
||||
}
|
||||
},
|
||||
mutations: {
|
||||
SET_AUTH_LABOR: (state, status) => {
|
||||
state.laborState = status
|
||||
setStore({
|
||||
name: 'laborState',
|
||||
content: state.laborState
|
||||
})
|
||||
},
|
||||
SET_AUTH_REALNAME: (state, status) => {
|
||||
state.realNameState = status
|
||||
setStore({
|
||||
name: 'realNameState',
|
||||
content: state.realNameState
|
||||
})
|
||||
},
|
||||
SET_AUTH_BANKCARD: (state, status) => {
|
||||
state.bankCardState = status
|
||||
setStore({
|
||||
name: 'bankCardState',
|
||||
content: state.bankCardState
|
||||
})
|
||||
},
|
||||
SET_AUTH_INSURE: (state, status) => {
|
||||
state.insureState = status
|
||||
setStore({
|
||||
name: 'insureState',
|
||||
content: state.insureState
|
||||
})
|
||||
},
|
||||
SET_AUTH_INFO: (state, data) => {
|
||||
state.authInfo = data
|
||||
setStore({
|
||||
name: 'authInfo',
|
||||
content: state.authInfo
|
||||
})
|
||||
},
|
||||
UPDATE_AUTH_INSURE_TYPE: (state, type) => {
|
||||
state.authInfo.bakValue = type
|
||||
setStore({
|
||||
name: 'authInfo',
|
||||
content: state.authInfo
|
||||
})
|
||||
},
|
||||
UPDATE_AUTH_REALNAME: (state, {
|
||||
realName,
|
||||
idNumber
|
||||
}) => {
|
||||
state.authInfo.realName = realName
|
||||
state.authInfo.idNumber = idNumber
|
||||
setStore({
|
||||
name: 'authInfo',
|
||||
content: state.authInfo
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
export default auth
|
||||
75
store/models/authentication.js
Normal file
75
store/models/authentication.js
Normal file
@@ -0,0 +1,75 @@
|
||||
import {
|
||||
getStore,
|
||||
setStore
|
||||
} from '@/untils/store.js'
|
||||
import {isGather} from '@/api/auth.js';
|
||||
const authentication = {
|
||||
state: {
|
||||
// 实名认证
|
||||
realName: {},
|
||||
// 银行卡印证
|
||||
bankCard: {},
|
||||
// 采集签名
|
||||
autograph: getStore({
|
||||
name: 'autograph'
|
||||
}) || {},
|
||||
},
|
||||
getters: {},
|
||||
actions: {
|
||||
setRealName({
|
||||
commit,
|
||||
getters
|
||||
}, realName){
|
||||
commit('SET_REALNAME', realName);
|
||||
},
|
||||
setBankCard({
|
||||
commit,
|
||||
getters
|
||||
}, bankCard){
|
||||
commit('SET_BACKCARD', bankCard);
|
||||
},
|
||||
setAutograph({
|
||||
commit,
|
||||
getters
|
||||
}){
|
||||
return new Promise((resolve, reject) => {
|
||||
isGather().then((res) => {
|
||||
const data = res.data
|
||||
commit('SET_AUTOGRAPH', data);
|
||||
resolve(res.data)
|
||||
}).catch(reject)
|
||||
})
|
||||
},
|
||||
clearAuthenication(){
|
||||
commit('SET_REALNAME', '');
|
||||
commit('SET_BACKCARD', '');
|
||||
commit('SET_AUTOGRAPH', '');
|
||||
}
|
||||
},
|
||||
mutations: {
|
||||
SET_REALNAME: (state, realName) => {
|
||||
state.realName = realName;
|
||||
setStore({
|
||||
name: 'realName',
|
||||
content: realName,
|
||||
type: 'session'
|
||||
})
|
||||
},
|
||||
SET_BACKCARD: (state, bankCard) => {
|
||||
setStore({
|
||||
name: 'bankCard',
|
||||
content: bankCard,
|
||||
type: 'session'
|
||||
})
|
||||
},
|
||||
SET_AUTOGRAPH: (state, autograph) => {
|
||||
state.autograph = autograph;
|
||||
setStore({
|
||||
name: 'autograph',
|
||||
content: autograph,
|
||||
type: 'session'
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
export default authentication
|
||||
32
store/models/face.js
Normal file
32
store/models/face.js
Normal file
@@ -0,0 +1,32 @@
|
||||
import {
|
||||
getStore,
|
||||
setStore
|
||||
} from '@/untils/store.js'
|
||||
|
||||
export default {
|
||||
state: {
|
||||
homeNavShow: getStore({
|
||||
name: 'homeNavShow'
|
||||
}) !== false,
|
||||
homeTitle: getStore({
|
||||
name: 'homeTitle'
|
||||
}) || '德阳市智慧就业服务平台'
|
||||
},
|
||||
actions: {},
|
||||
mutations: {
|
||||
SET_HOME_TITLE: (state, status) => {
|
||||
state.homeTitle = status
|
||||
setStore({
|
||||
name: 'homeTitle',
|
||||
content: state.homeTitle
|
||||
})
|
||||
},
|
||||
SET_HOME_NAV_SHOW: (state, status) => {
|
||||
state.homeNavShow = status
|
||||
setStore({
|
||||
name: 'homeNavShow',
|
||||
content: state.homeNavShow
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
283
store/models/news.js
Normal file
283
store/models/news.js
Normal file
@@ -0,0 +1,283 @@
|
||||
import {
|
||||
inviteCount,
|
||||
inviteList,
|
||||
inviteRead,
|
||||
inviteRemove,
|
||||
noticeCount,
|
||||
noticeList,
|
||||
noticeRead,
|
||||
noticeRemove
|
||||
} from '@/api/news.js'
|
||||
import website from '@/config/website.js'
|
||||
const size = 20
|
||||
const handler = {
|
||||
'0': {
|
||||
count: noticeCount,
|
||||
getList: noticeList,
|
||||
read: noticeRead,
|
||||
remove: noticeRemove
|
||||
},
|
||||
'1': {
|
||||
count: inviteCount,
|
||||
getList: inviteList,
|
||||
read: inviteRead,
|
||||
remove: inviteRemove
|
||||
}
|
||||
}
|
||||
|
||||
function getCount(data) {
|
||||
let sum = 0
|
||||
for (let key in data) {
|
||||
sum += data[key]
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
let refreshTimer = null;
|
||||
|
||||
function startRefreshToken(dispatch) {
|
||||
refreshTimer = setInterval(() => {
|
||||
dispatch("newsInit");
|
||||
}, website.newsRefreshTime);
|
||||
}
|
||||
|
||||
function stopRefreshToken() {
|
||||
clearInterval(refreshTimer)
|
||||
}
|
||||
|
||||
const news = {
|
||||
state: {
|
||||
count: 0,
|
||||
data: {
|
||||
"0": {
|
||||
id: "0",
|
||||
title: "通知",
|
||||
icon: "../../static/img/notice.svg",
|
||||
page: {
|
||||
current: 0,
|
||||
size,
|
||||
total: size
|
||||
},
|
||||
data: [],
|
||||
prop: {
|
||||
title: 'title',
|
||||
desc: (value) => {
|
||||
if (value.data[0])
|
||||
return value.data[0][0]['desc']
|
||||
},
|
||||
time: 'createTime',
|
||||
isRead: 'isRead',
|
||||
listDesc: 'desc',
|
||||
},
|
||||
navigateTo(item) {
|
||||
uni.$once('getNewsDetail', (cb) => {
|
||||
cb(item)
|
||||
})
|
||||
uni.navigateTo({
|
||||
url: "/pages/news/newsDetail?type=0"
|
||||
})
|
||||
}
|
||||
},
|
||||
"1": {
|
||||
id: "1",
|
||||
title: "任务邀请",
|
||||
icon: "../../static/img/invite.svg",
|
||||
page: {
|
||||
current: 0,
|
||||
size,
|
||||
total: size
|
||||
},
|
||||
data: [],
|
||||
prop: {
|
||||
title: 'missionTitle',
|
||||
desc: (value) => {
|
||||
if (value.data[0])
|
||||
return `您收到${value.data[0][0]['companyName']}的任务`
|
||||
},
|
||||
time: 'createTime',
|
||||
isRead: 'status',
|
||||
listDesc: 'companyName',
|
||||
},
|
||||
navigateTo(item, dispatch) {
|
||||
dispatch('readNew', {
|
||||
key: '1',
|
||||
id: item.id
|
||||
})
|
||||
uni.navigateTo({
|
||||
url: `/pages/projectInfo/projectInfo?type=1&missionNo=${encodeURIComponent(item.missionNo)}&id=${encodeURIComponent(item.id)}`
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
unread: {
|
||||
"0": 0,
|
||||
"1": 0
|
||||
},
|
||||
allUnread: 0,
|
||||
dic: {}
|
||||
},
|
||||
actions: {
|
||||
newsInit({
|
||||
dispatch
|
||||
}) {
|
||||
const ps = []
|
||||
ps.push(dispatch('getUnreadNum'))
|
||||
|
||||
for (let key in handler) {
|
||||
ps.push(dispatch('newsReload', key))
|
||||
}
|
||||
return Promise.all(ps)
|
||||
},
|
||||
newsReload({
|
||||
dispatch,
|
||||
commit
|
||||
}, id) {
|
||||
commit('CLEAR_NEWS_DATA', id)
|
||||
return dispatch('newsGetNextPage', id)
|
||||
},
|
||||
getUnreadNum({
|
||||
commit
|
||||
}) {
|
||||
for (let key in handler) {
|
||||
handler[key].count().then((result) => {
|
||||
commit('SET_UNREADNUM', {
|
||||
id: key,
|
||||
count: result
|
||||
})
|
||||
})
|
||||
}
|
||||
},
|
||||
newsGetNextPage({
|
||||
state,
|
||||
commit
|
||||
}, id) {
|
||||
const item = state.data[id]
|
||||
const page = item.page
|
||||
const current = page.current + 1
|
||||
return new Promise((resolve, reject) => {
|
||||
if (parseInt(page.total / page.size) + 1 < current) {
|
||||
resolve()
|
||||
return
|
||||
}
|
||||
handler[id].getList(current, page.size).then(res => {
|
||||
const data = res.data.data;
|
||||
commit('ADD_NEWS_DATA', {
|
||||
id,
|
||||
data: data.records,
|
||||
current,
|
||||
total: data.total
|
||||
})
|
||||
resolve(res)
|
||||
}).catch(reject)
|
||||
})
|
||||
},
|
||||
removeNew({
|
||||
commit
|
||||
}, {
|
||||
id,
|
||||
key,
|
||||
group,
|
||||
index
|
||||
}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
commit('REMOVE_NEWS', {
|
||||
id,
|
||||
key,
|
||||
group,
|
||||
index
|
||||
})
|
||||
handler[key].remove(id).then(resolve, reject)
|
||||
})
|
||||
},
|
||||
readNew({
|
||||
commit
|
||||
}, {
|
||||
key,
|
||||
id
|
||||
}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
commit('READ_NEWS', {
|
||||
key,
|
||||
id
|
||||
})
|
||||
handler[key].read(id).then(resolve, reject)
|
||||
})
|
||||
},
|
||||
endRefreshNewsTimer(){
|
||||
stopRefreshToken()
|
||||
},
|
||||
startRefreshNewsTimer({
|
||||
state,
|
||||
commit,
|
||||
dispatch
|
||||
}) {
|
||||
dispatch('newsInit').then(() => {
|
||||
startRefreshToken(dispatch);
|
||||
})
|
||||
}
|
||||
},
|
||||
mutations: {
|
||||
SET_UNREADNUM: (state, {
|
||||
id,
|
||||
count
|
||||
}) => {
|
||||
state.unread[id] = count
|
||||
state.allUnread = getCount(state.unread)
|
||||
},
|
||||
CLEAR_NEWS_DATA: (state, id) => {
|
||||
state.data[id].page = {
|
||||
current: 0,
|
||||
size
|
||||
}
|
||||
state.data[id].data = []
|
||||
},
|
||||
ADD_NEWS_DATA: (state, {
|
||||
id,
|
||||
data,
|
||||
current,
|
||||
total
|
||||
}) => {
|
||||
data.forEach(item => {
|
||||
state.dic[item.id] = item
|
||||
})
|
||||
state.data[id].page.total = total
|
||||
state.data[id].page.current = current
|
||||
if (data.length > 0) {
|
||||
state.data[id].data.push(data)
|
||||
}
|
||||
},
|
||||
REMOVE_NEWS: (state, {
|
||||
id,
|
||||
key,
|
||||
group,
|
||||
index
|
||||
}) => {
|
||||
const readProp = state.data[key].prop['isRead']
|
||||
if (state.dic[id][readProp] === 0) {
|
||||
state.unread[key]--
|
||||
state.allUnread--
|
||||
}
|
||||
state.dic[id] = undefined
|
||||
const data = state.data[key].data
|
||||
data[group].splice(index, 1)
|
||||
if (data[group].length === 0) {
|
||||
data.splice(group, 1)
|
||||
}
|
||||
},
|
||||
READ_NEWS: (state, {
|
||||
key,
|
||||
id
|
||||
}) => {
|
||||
const readProp = state.data[key].prop['isRead']
|
||||
if (state.dic[id][readProp] === 0) {
|
||||
state.dic[id][readProp] = 1
|
||||
state.unread[key]--
|
||||
state.allUnread--
|
||||
}
|
||||
}
|
||||
},
|
||||
getters: {
|
||||
|
||||
}
|
||||
};
|
||||
export default news;
|
||||
230
store/models/user.js
Normal file
230
store/models/user.js
Normal file
@@ -0,0 +1,230 @@
|
||||
import {
|
||||
isURL,
|
||||
validatenull
|
||||
} from '@/untils/validate.js'
|
||||
import website from '@/config/website'
|
||||
import {
|
||||
loginByUsername,
|
||||
getUserInfo,
|
||||
logout,
|
||||
refreshToken
|
||||
} from '@/api/user'
|
||||
import md5 from 'js-md5'
|
||||
import {
|
||||
getStore,
|
||||
setStore
|
||||
} from '@/untils/store.js'
|
||||
import {
|
||||
calcDate
|
||||
} from '@/untils/date.js'
|
||||
|
||||
let refreshTimer = null;
|
||||
|
||||
function startRefreshToken(dispatch) {
|
||||
refreshTimer = setInterval(() => {
|
||||
const token =
|
||||
getStore({
|
||||
name: "token",
|
||||
debug: true
|
||||
}) || {};
|
||||
const date = calcDate(token.datetime, new Date().getTime());
|
||||
if (validatenull(date)) return;
|
||||
if (date.seconds >= website.tokenTime) {
|
||||
dispatch("refreshToken")
|
||||
.then(() => {})
|
||||
.catch(() => {});
|
||||
}
|
||||
}, 10000);
|
||||
}
|
||||
|
||||
function stopRefreshToken() {
|
||||
clearInterval(refreshTimer)
|
||||
}
|
||||
|
||||
const user = {
|
||||
state: {
|
||||
tenantId: getStore({
|
||||
name: 'tenantId'
|
||||
}) || '',
|
||||
userInfo: getStore({
|
||||
name: 'userInfo'
|
||||
}) || [],
|
||||
token: getStore({
|
||||
name: 'token'
|
||||
}) || '',
|
||||
refreshToken: getStore({
|
||||
name: 'refreshToken'
|
||||
}) || '',
|
||||
userChecked:getStore({
|
||||
name: 'setUserCheckValue'
|
||||
}) || false,
|
||||
sendTimes:getStore({//用户发送短信次数
|
||||
name:'setUserSendTimes'
|
||||
}) || 0,
|
||||
},
|
||||
actions: {
|
||||
//用户点击radio按钮
|
||||
UserCheckedBtn({commit},val){
|
||||
commit('SET_USER_CHECKED',val);
|
||||
},
|
||||
//根据用户名登录
|
||||
LoginByUsername({
|
||||
commit,
|
||||
dispatch
|
||||
}, userInfo) {
|
||||
return new Promise((resolve, reject) => {
|
||||
loginByUsername(userInfo.tenantId, userInfo.username, md5(userInfo.password), userInfo.type, userInfo.key,
|
||||
userInfo.code).then(res => {
|
||||
const data = res.data;
|
||||
if (data.error_description) {
|
||||
uni.showToast({
|
||||
icon: "none",
|
||||
title: data.error_description,
|
||||
})
|
||||
} else {
|
||||
commit('SET_TOKEN', data.access_token);
|
||||
commit('SET_REFRESH_TOKEN', data.refresh_token);
|
||||
commit('SET_TENANT_ID', data.tenant_id);
|
||||
commit('SET_USER_INFO', data);
|
||||
dispatch('refreshAuthState')
|
||||
dispatch('startRefreshNewsTimer')
|
||||
startRefreshToken();
|
||||
}
|
||||
resolve(res);
|
||||
}).catch(error => {
|
||||
reject(error);
|
||||
})
|
||||
})
|
||||
},
|
||||
//根据手机号登录
|
||||
LoginByPhone({
|
||||
commit
|
||||
}, userInfo) {
|
||||
return new Promise((resolve) => {
|
||||
loginByUsername(userInfo.phone, userInfo.code).then(res => {
|
||||
const data = res.data.data;
|
||||
commit('SET_TOKEN', data);
|
||||
resolve();
|
||||
})
|
||||
})
|
||||
},
|
||||
GetUserInfo({
|
||||
commit
|
||||
}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
getUserInfo().then((res) => {
|
||||
const data = res.data.data;
|
||||
resolve(data);
|
||||
}).catch(err => {
|
||||
reject(err);
|
||||
})
|
||||
})
|
||||
},
|
||||
//刷新token
|
||||
refreshToken({
|
||||
state,
|
||||
commit,
|
||||
dispatch
|
||||
}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
refreshToken(state.refreshToken, state.tenantId).then(res => {
|
||||
const data = res.data;
|
||||
dispatch('refreshAuthState')
|
||||
commit('SET_TOKEN', data.access_token);
|
||||
commit('SET_REFRESH_TOKEN', data.refresh_token);
|
||||
resolve();
|
||||
}).catch(error => {
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
},
|
||||
// 登出
|
||||
LogOut({
|
||||
dispatch,
|
||||
commit
|
||||
}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
logout();
|
||||
stopRefreshToken();
|
||||
commit('SET_TOKEN', '');
|
||||
commit('SET_VIPCODE', '0');
|
||||
resolve();
|
||||
})
|
||||
},
|
||||
//注销session
|
||||
FedLogOut({
|
||||
commit
|
||||
}) {
|
||||
return new Promise(resolve => {
|
||||
commit('SET_TOKEN', '');
|
||||
resolve();
|
||||
})
|
||||
},
|
||||
startRefreshTokenTimer({
|
||||
state,
|
||||
commit,
|
||||
dispatch
|
||||
}) {
|
||||
if (state.token) {
|
||||
dispatch('refreshToken').then(() => {
|
||||
startRefreshToken(dispatch);
|
||||
})
|
||||
}
|
||||
},
|
||||
//更新用户接收短信次数
|
||||
UpdateUserSendTimes({
|
||||
commit
|
||||
}, data) {
|
||||
commit('SET_USER_SENDTIMES',data);
|
||||
},
|
||||
},
|
||||
mutations: {
|
||||
SET_TOKEN: (state, token) => {
|
||||
state.token = token;
|
||||
setStore({
|
||||
name: 'token',
|
||||
content: state.token,
|
||||
type: 'session'
|
||||
})
|
||||
},
|
||||
SET_REFRESH_TOKEN: (state, refreshToken) => {
|
||||
state.refreshToken = refreshToken;
|
||||
setStore({
|
||||
name: 'refreshToken',
|
||||
content: state.refreshToken,
|
||||
type: 'session'
|
||||
})
|
||||
},
|
||||
SET_TENANT_ID: (state, tenantId) => {
|
||||
state.tenantId = tenantId;
|
||||
setStore({
|
||||
name: 'tenantId',
|
||||
content: state.tenantId,
|
||||
type: 'session'
|
||||
})
|
||||
},
|
||||
SET_USER_INFO: (state, userInfo) => {
|
||||
state.userInfo = userInfo;
|
||||
setStore({
|
||||
name: 'userInfo',
|
||||
content: state.userInfo
|
||||
})
|
||||
},
|
||||
SET_USER_CHECKED:(state,val)=>{
|
||||
state.userChecked=val;
|
||||
setStore({
|
||||
name: 'setUserCheckValue',
|
||||
content: state.userChecked
|
||||
})
|
||||
},
|
||||
SET_USER_SENDTIMES:(state,val)=>{
|
||||
state.sendTimes=val;
|
||||
setStore({
|
||||
name: 'setUserSendTimes',
|
||||
content: state.sendTimes
|
||||
})
|
||||
},
|
||||
|
||||
}
|
||||
}
|
||||
export default user
|
||||
69
store/models/vip.js
Normal file
69
store/models/vip.js
Normal file
@@ -0,0 +1,69 @@
|
||||
import {
|
||||
getStore,
|
||||
setStore
|
||||
} from '@/untils/store.js'
|
||||
import {
|
||||
getVipCode,
|
||||
bindVip
|
||||
} from "@/api/vip.js"
|
||||
|
||||
const user = {
|
||||
state: {
|
||||
vipCode: getStore({
|
||||
name: 'vipCode'
|
||||
}) || '0',
|
||||
},
|
||||
getters: {
|
||||
isVip(state) {
|
||||
return state.vipCode != '0'
|
||||
},
|
||||
vipCode(state) {
|
||||
return state.vipCode
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
getVipCode({
|
||||
commit,
|
||||
getters
|
||||
}, idNumber) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (getters.isVip) {
|
||||
resolve();
|
||||
} else if(getters.authInfo.idNumber) {
|
||||
getVipCode(getters.authInfo.idNumber).then(res => {
|
||||
commit('SET_VIPCODE', res.data.data);
|
||||
resolve();
|
||||
}).catch(error => {
|
||||
reject(error);
|
||||
})
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
})
|
||||
},
|
||||
bindVipCode({
|
||||
commit,
|
||||
getters
|
||||
}, code) {
|
||||
return new Promise((resolve, reject) => {
|
||||
bindVip(getters.authInfo.idNumber, code).then(res => {
|
||||
commit('SET_VIPCODE', code);
|
||||
resolve();
|
||||
}).catch(error => {
|
||||
reject(error);
|
||||
})
|
||||
})
|
||||
}
|
||||
},
|
||||
mutations: {
|
||||
SET_VIPCODE: (state, code) => {
|
||||
state.vipCode = code;
|
||||
setStore({
|
||||
name: 'vipCode',
|
||||
content: code,
|
||||
type: 'session'
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
export default user
|
||||
Reference in New Issue
Block a user