Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修改 store 中错误返回 #49

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
240 changes: 120 additions & 120 deletions store/index.js
Original file line number Diff line number Diff line change
@@ -1,125 +1,125 @@
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
state: {
hasLogin: false,
isUniverifyLogin: false,
loginProvider: "",
openid: null,
testvuex: false,
colorIndex: 0,
colorList: ['#FF0000', '#00FF00', '#0000FF'],
noMatchLeftWindow: true,
active: 'componentPage',
leftWinActive: '/pages/component/view/view',
activeOpen: '',
import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
state: {
hasLogin: false,
isUniverifyLogin: false,
loginProvider: "",
openid: null,
testvuex: false,
colorIndex: 0,
colorList: ['#FF0000', '#00FF00', '#0000FF'],
noMatchLeftWindow: true,
active: 'componentPage',
leftWinActive: '/pages/component/view/view',
activeOpen: '',
menu: [],
univerifyErrorMsg: ''
},
mutations: {
login(state, provider) {
state.hasLogin = true;
state.loginProvider = provider;
},
logout(state) {
state.hasLogin = false
state.openid = null
},
setOpenid(state, openid) {
state.openid = openid
},
setTestTrue(state) {
state.testvuex = true
},
setTestFalse(state) {
state.testvuex = false
},
setColorIndex(state, index) {
state.colorIndex = index
},
setMatchLeftWindow(state, matchLeftWindow) {
state.noMatchLeftWindow = !matchLeftWindow
},
setActive(state, tabPage) {
state.active = tabPage
},
setLeftWinActive(state, leftWinActive) {
state.leftWinActive = leftWinActive
},
setActiveOpen(state, activeOpen) {
state.activeOpen = activeOpen
},
setMenu(state, menu) {
state.menu = menu
},
setUniverifyLogin(state, payload) {
typeof payload !== 'boolean' ? payload = !!payload : '';
state.isUniverifyLogin = payload;
univerifyErrorMsg: ''
},
mutations: {
login(state, provider) {
state.hasLogin = true;
state.loginProvider = provider;
},
logout(state) {
state.hasLogin = false
state.openid = null
},
setOpenid(state, openid) {
state.openid = openid
},
setTestTrue(state) {
state.testvuex = true
},
setTestFalse(state) {
state.testvuex = false
},
setColorIndex(state, index) {
state.colorIndex = index
},
setMatchLeftWindow(state, matchLeftWindow) {
state.noMatchLeftWindow = !matchLeftWindow
},
setActive(state, tabPage) {
state.active = tabPage
},
setLeftWinActive(state, leftWinActive) {
state.leftWinActive = leftWinActive
},
setActiveOpen(state, activeOpen) {
state.activeOpen = activeOpen
},
setMenu(state, menu) {
state.menu = menu
},
setUniverifyLogin(state, payload) {
typeof payload !== 'boolean' ? payload = !!payload : '';
state.isUniverifyLogin = payload;
},
setUniverifyErrorMsg(state,payload = ''){
state.univerifyErrorMsg = payload
}
},
getters: {
currentColor(state) {
return state.colorList[state.colorIndex]
}
},
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)
}
})
}
})
},
getPhoneNumber: function({
commit
}, univerifyInfo) {
return new Promise((resolve, reject) => {
uni.request({
url: 'https://97fca9f2-41f6-449f-a35e-3f135d4c3875.bspapp.com/http/univerify-login',
method: 'POST',
data: univerifyInfo,
success: (res) => {
const data = res.data
if (data.success) {
resolve(data.phoneNumber)
} else {
reject(res)
}
},
fail: (err) => {
reject(res)
}
})
})
}
}
})
}
},
getters: {
currentColor(state) {
return state.colorList[state.colorIndex]
}
},
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)
}
})
}
})
},
getPhoneNumber: function({
commit
}, univerifyInfo) {
return new Promise((resolve, reject) => {
uni.request({
url: 'https://97fca9f2-41f6-449f-a35e-3f135d4c3875.bspapp.com/http/univerify-login',
method: 'POST',
data: univerifyInfo,
success: (res) => {
const data = res.data
if (data.success) {
resolve(data.phoneNumber)
} else {
reject(res)
}

},
fail: (err) => {
reject(err)
}
})
})
}
}
})

export default store