酷炫直播运营系统小程序版本

index.js 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. import { req,rootDocment } from '../config/util.js'
  4. import { api } from '../config/api.js'
  5. Vue.use(Vuex)
  6. Vue.prototype.$req = req
  7. Vue.prototype.$api = api
  8. Vue.prototype.$rootDocment = rootDocment
  9. var md5 = require('../config/md5.js');
  10. const store = new Vuex.Store({
  11. state: {
  12. staffList:[],//工作人员列表
  13. hasLogin: false,//是否登录
  14. loginProvider: "",//登录的平台 - 目前只是微信小程序
  15. systemInfo:{},//系统信息
  16. brandCategoryList:[],//品牌分类数据
  17. colorIndex: 0,
  18. colorList: ['#FF0000', '#00FF00', '#0000FF'],
  19. noMatchLeftWindow: true,
  20. active: 'componentPage',
  21. leftWinActive: '/pages/component/view/view',
  22. activeOpen: '',
  23. menu: [],
  24. univerifyErrorMsg: ''
  25. },
  26. mutations: {
  27. login(state, provider) {
  28. state.hasLogin = true;
  29. state.loginProvider = provider;
  30. },
  31. setSystemInfo(state,data){//设置系统信息
  32. state.systemInfo = data
  33. },
  34. logout(state) {
  35. state.hasLogin = false
  36. state.openid = null
  37. },
  38. setOpenid(state, openid) {
  39. state.openid = openid
  40. },
  41. setColorIndex(state, index) {
  42. state.colorIndex = index
  43. },
  44. setMatchLeftWindow(state, matchLeftWindow) {
  45. state.noMatchLeftWindow = !matchLeftWindow
  46. },
  47. setActive(state, tabPage) {
  48. state.active = tabPage
  49. },
  50. setLeftWinActive(state, leftWinActive) {
  51. state.leftWinActive = leftWinActive
  52. },
  53. setActiveOpen(state, activeOpen) {
  54. state.activeOpen = activeOpen
  55. },
  56. setMenu(state, menu) {
  57. state.menu = menu
  58. },
  59. setUniverifyLogin(state, payload) {
  60. typeof payload !== 'boolean' ? payload = !!payload : '';
  61. state.isUniverifyLogin = payload;
  62. },
  63. setUniverifyErrorMsg(state,payload = ''){
  64. state.univerifyErrorMsg = payload
  65. }
  66. },
  67. getters: {
  68. currentColor(state) {
  69. return state.colorList[state.colorIndex]
  70. }
  71. },
  72. actions: {
  73. // lazy loading openid
  74. //loginInfo {'encrypted_data':encrypted_data,'iv':iv,'provider':provider}
  75. getUserInfo_login: async function({commit,state},loginInfo) {
  76. return await new Promise((resolve, reject) => {
  77. console.log((loginInfo.iv),'loginInfo')
  78. uni.login({
  79. 'provider':loginInfo.provider,
  80. success: (data) => {
  81. if(data.code){
  82. req(api.LOGIN,'get',{
  83. 'code': data.code,
  84. 'iv': loginInfo.iv,
  85. 'encrypted_data': loginInfo.encryptedData,
  86. },function(res){
  87. if(res && res.errno == 0){
  88. commit('login')
  89. uni.setStorageSync('session_key',res.rst.session_key)
  90. uni.setStorageSync('isLogin',true)
  91. state.userInfo = res.rst.info
  92. uni.setStorageSync('admin_id',res.rst.info.id)
  93. uni.setStorageSync('ttl',res.rst.ttl)
  94. var sign=md5.hex_md5("random="+res.rst.random+"&ttl="+res.rst.ttl+"&user_id="+res.rst.info.id);
  95. uni.setStorageSync('sign',sign)
  96. resolve()
  97. }else{
  98. reject({err:'interface',info:res.err})
  99. }
  100. })
  101. }else{
  102. reject({err:'code获取失败'})
  103. }
  104. },
  105. fail: (err) => {
  106. console.log('uni.login 接口调用失败,将无法正常使用开放接口等服务', err)
  107. reject({err:'uni.login失败',info:err})
  108. }
  109. })
  110. })
  111. },
  112. login_verified: function({commit}) {//过审核接口
  113. return new Promise((resolve, reject) => {
  114. req(api.verified,'get',{
  115. 'version': 'v1.4',
  116. },function(res){
  117. if(res && res.errno == 0){
  118. let data = res.rst.data;
  119. uni.setStorageSync('session_key',data.session_key)
  120. uni.setStorageSync('isLogin', true)
  121. uni.setStorageSync('userInfo', data)
  122. uni.setStorageSync('admin_id', data.info.id)
  123. uni.setStorageSync('ttl', data.ttl)
  124. var sign = md5.hex_md5("random=" + data.random + "&ttl=" + data.ttl + "&user_id=" + data.info.id);
  125. uni.setStorageSync('sign', sign)
  126. uni.setStorageSync('user_type', data.info.user_type)
  127. resolve()
  128. }else if(res.errno == 9014){
  129. reject()
  130. }
  131. },(err)=>{
  132. reject()
  133. })
  134. })
  135. },
  136. login_first:function({commit,state}){//首次进入,登录
  137. return new Promise((resolve, reject) => {
  138. uni.login({
  139. success: (data) => {
  140. console.log(data)
  141. // req(api.loginByUnionId,'get',{
  142. // 'code': data.code,
  143. // },function(res){
  144. // if(res && res.errno == 0){
  145. // commit('login')
  146. // uni.setStorageSync('session_key',res.rst.session_key)
  147. // uni.setStorageSync('isLogin',true)
  148. // state.userInfo = res.rst.info
  149. // uni.setStorageSync('admin_id',res.rst.info.id)
  150. // uni.setStorageSync('ttl',res.rst.ttl)
  151. // var sign=md5.hex_md5("random="+res.rst.random+"&ttl="+res.rst.ttl+"&user_id="+res.rst.info.id);
  152. // uni.setStorageSync('sign',sign)
  153. // resolve()
  154. // }else{
  155. // }
  156. // },(err)=>{
  157. // })
  158. }
  159. })
  160. })
  161. }
  162. }
  163. })
  164. export default store