123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- import Vue from 'vue'
- import Vuex from 'vuex'
- import { req,rootDocment } from '../config/util.js'
- import { api } from '../config/api.js'
- Vue.use(Vuex)
- Vue.prototype.$req = req
- Vue.prototype.$api = api
- Vue.prototype.$rootDocment = rootDocment
- var md5 = require('../config/md5.js');
- const store = new Vuex.Store({
- state: {
- staffList:[],//工作人员列表
- hasLogin: false,//是否登录
- loginProvider: "",//登录的平台 - 目前只是微信小程序
- systemInfo:{},//系统信息
- brandCategoryList:[],//品牌分类数据
- 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;
- },
- setSystemInfo(state,data){//设置系统信息
- state.systemInfo = data
- },
- logout(state) {
- state.hasLogin = false
- state.openid = null
- },
- setOpenid(state, openid) {
- state.openid = openid
- },
- 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
- //loginInfo {'encrypted_data':encrypted_data,'iv':iv,'provider':provider}
- getUserInfo_login: async function({commit,state},loginInfo) {
- return await new Promise((resolve, reject) => {
- console.log((loginInfo.iv),'loginInfo')
- uni.login({
- 'provider':loginInfo.provider,
- success: (data) => {
- if(data.code){
- req(api.LOGIN,'get',{
- 'code': data.code,
- 'iv': loginInfo.iv,
- 'encrypted_data': loginInfo.encryptedData,
- },function(res){
- if(res && res.errno == 0){
- commit('login')
- uni.setStorageSync('session_key',res.rst.session_key)
- uni.setStorageSync('isLogin',true)
- state.userInfo = res.rst.info
- uni.setStorageSync('admin_id',res.rst.info.id)
- uni.setStorageSync('ttl',res.rst.ttl)
- var sign=md5.hex_md5("random="+res.rst.random+"&ttl="+res.rst.ttl+"&user_id="+res.rst.info.id);
- uni.setStorageSync('sign',sign)
- resolve()
- }else{
- reject({err:'interface',info:res.err})
- }
- })
- }else{
- reject({err:'code获取失败'})
- }
- },
- fail: (err) => {
- console.log('uni.login 接口调用失败,将无法正常使用开放接口等服务', err)
- reject({err:'uni.login失败',info:err})
- }
- })
- })
- },
- login_verified: function({commit}) {//过审核接口
- return new Promise((resolve, reject) => {
- req(api.verified,'get',{
- 'version': 'v1.4',
- },function(res){
- if(res && res.errno == 0){
- let data = res.rst.data;
- uni.setStorageSync('session_key',data.session_key)
- uni.setStorageSync('isLogin', true)
- uni.setStorageSync('userInfo', data)
- uni.setStorageSync('admin_id', data.info.id)
- uni.setStorageSync('ttl', data.ttl)
- var sign = md5.hex_md5("random=" + data.random + "&ttl=" + data.ttl + "&user_id=" + data.info.id);
- uni.setStorageSync('sign', sign)
- uni.setStorageSync('user_type', data.info.user_type)
- resolve()
- }else if(res.errno == 9014){
- reject()
- }
- },(err)=>{
- reject()
- })
- })
- },
- login_first:function({commit,state}){//首次进入,登录
- return new Promise((resolve, reject) => {
- uni.login({
- success: (data) => {
- console.log(data)
- // req(api.loginByUnionId,'get',{
- // 'code': data.code,
- // },function(res){
- // if(res && res.errno == 0){
- // commit('login')
- // uni.setStorageSync('session_key',res.rst.session_key)
- // uni.setStorageSync('isLogin',true)
- // state.userInfo = res.rst.info
- // uni.setStorageSync('admin_id',res.rst.info.id)
- // uni.setStorageSync('ttl',res.rst.ttl)
- // var sign=md5.hex_md5("random="+res.rst.random+"&ttl="+res.rst.ttl+"&user_id="+res.rst.info.id);
- // uni.setStorageSync('sign',sign)
- // resolve()
- // }else{
-
- // }
- // },(err)=>{
-
- // })
- }
- })
-
- })
- }
- }
- })
- export default store
|