index.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. import api from "@/api/api"
  4. import MinCache from'@/common/util/MinCache.js'
  5. import { ACCESS_TOKEN,USER_NAME,USER_INFO } from "@/common/util/constants"
  6. Vue.use(Vuex)
  7. export default new Vuex.Store({
  8. state: {
  9. token: localStorage.getItem('token')||'',
  10. sessionId:localStorage.getItem('sessionId')||'',
  11. indexId:localStorage.getItem('indexId')||'',
  12. userid:localStorage.getItem('userid')||'',
  13. username:localStorage.getItem('username')||'',
  14. realname: localStorage.getItem('realname')||'',
  15. welcome: localStorage.getItem('welcome')||'',
  16. avatar:localStorage.getItem('avatar')||'',
  17. orgCode:localStorage.getItem('orgCode')||'',
  18. rzdate:localStorage.getItem('rzdate')||'',//入职时间
  19. birthdate:localStorage.getItem('birthdate')||'',//生日
  20. id:localStorage.getItem('id')||'',//查看考勤人员id
  21. date:localStorage.getItem('date')||'',//查看考勤人员日期
  22. departId:localStorage.getItem('departId')||'',//查询部门人员信息id
  23. teamUserId:localStorage.getItem('teamUserId')||'',//查看团队人员信息id
  24. tmsUserId:localStorage.getItem('tmsUserId')||'',//查看团队人员个人信息id
  25. wagesDate:localStorage.getItem('wagesDate')||'',//查看个人工资参数
  26. wagesId:localStorage.getItem('wagesId')||'',//查看个人工资参数人事
  27. emilCode:localStorage.getItem('emilCode')||'',//邮箱验证码
  28. chatname:localStorage.getItem('chatname')||'',//邮箱验证码
  29. chatid:localStorage.getItem('chatid')||'',
  30. perssion:localStorage.getItem('perssion')||'',//菜单数据
  31. leave:localStorage.getItem('leave')||'',//部门假期
  32. status:localStorage.getItem('status')||'',//人员类别
  33. },
  34. mutations: {
  35. SET_STATUS: (state, status) => {
  36. localStorage.setItem('status',status)
  37. state.status = status
  38. },
  39. SET_USERID: (state, userid) => {
  40. localStorage.setItem('userid',userid)
  41. state.userid = userid
  42. },
  43. SET_LEAVE: (state, leave) => {
  44. localStorage .setItem('leave',leave)
  45. state.leave = leave
  46. },
  47. SET_CHAT: (state, {chatname,chatid,chatimg}) => {
  48. localStorage.setItem('chatname',chatname)
  49. localStorage.setItem('chatid',chatid)
  50. localStorage.setItem('chatimg',chatimg)
  51. state.chatname = chatname
  52. state.chatid=chatid
  53. },
  54. SET_INDEXID: (state, indexId) => {
  55. localStorage.setItem('indexId',indexId)
  56. state.indexId = indexId
  57. },
  58. SET_TOKEN: (state, token) => {
  59. localStorage.setItem('token',token)
  60. state.token = token
  61. },
  62. SET_SESSIONID: (state, sessionId) => {
  63. localStorage.setItem('sessionId',sessionId)
  64. state.sessionId = sessionId
  65. },
  66. SET_NAME: (state, { username, realname, welcome }) => {
  67. localStorage.setItem('sessionId',username)
  68. localStorage.setItem('sessionId',realname)
  69. localStorage.setItem('sessionId',welcome)
  70. state.username = username
  71. state.realname = realname
  72. state.welcome = welcome
  73. },
  74. SET_RZDATE: (state,rzdate) => {
  75. localStorage.setItem('rzdate',rzdate)
  76. state.rzdate = rzdate
  77. },
  78. SET_NPMUSER: (state, {id,date}) => {
  79. localStorage.setItem('id',id)
  80. localStorage.setItem('date',date)
  81. state.id = id
  82. state.date = date
  83. },
  84. SET_AVATAR: (state, avatar) => {
  85. localStorage .setItem('avatar',avatar)
  86. state.avatar = avatar
  87. },
  88. SET_DEPARTID: (state,departId) => {
  89. localStorage.setItem('departId',departId)
  90. state.departId = departId
  91. },
  92. SET_TEAMUSERID: (state,teamUserId) => {
  93. localStorage.setItem('teamUserId',teamUserId)
  94. state.teamUserId = teamUserId
  95. },
  96. SET_TEMUSERID: (state,tmsUserId) => {
  97. localStorage.setItem('tmsUserId',tmsUserId)
  98. state.tmsUserId = tmsUserId
  99. },
  100. SET_WAGESDATE: (state,wagesDate) => {
  101. localStorage.setItem('wagesDate',wagesDate)
  102. state.wagesDate = wagesDate
  103. },
  104. SET_WAGESID: (state,wagesId) => {
  105. localStorage.setItem('wagesId',wagesId)
  106. state.wagesId = wagesId
  107. },
  108. SET_BIRTHDATE: (state,birthdate) => {
  109. localStorage.setItem('birthdate',birthdate)
  110. state.birthdate = birthdate
  111. },
  112. SET_EMILCODE: (state,emilCode) => {
  113. localStorage.setItem('emilCode',emilCode)
  114. state.emilCode = emilCode
  115. },
  116. SET_PERSSION:(state,perssion) => {
  117. sessionStorage.setItem('perssion',perssion)
  118. state.perssion = perssion
  119. },
  120. },
  121. actions: {
  122. // 登录
  123. mLogin({ commit }, userInfo) {
  124. console.log("mLogin",userInfo)
  125. return new Promise((resolve, reject) => {
  126. api.login(userInfo).then(response => {
  127. if(response.data.code ==200){
  128. const result = response.data.result
  129. const userInfo = result.userInfo
  130. let avatar=(userInfo.avatar && userInfo.avatar.length > 0)? api.getFileAccessHttpUrl(userInfo.avatar):'/static/avatar_boy.png'
  131. uni.setStorageSync(ACCESS_TOKEN,result.token);
  132. uni.setStorageSync(USER_INFO,userInfo);
  133. commit('SET_PERSSION', result.permission)
  134. commit('SET_TOKEN', result.token)
  135. commit('SET_SESSIONID', result.sessionId)
  136. commit('SET_AVATAR', avatar)
  137. commit('SET_USERID',userInfo.id)
  138. commit('SET_NAME', { username: userInfo.username,realname: userInfo.realname})
  139. commit('SET_RZDATE',userInfo.entryDate)
  140. commit('SET_BIRTHDATE',userInfo.birthday)
  141. resolve(response)
  142. }else{
  143. resolve(response)
  144. }
  145. }).catch(error => {
  146. console.log("catch===>response",response)
  147. reject(error)
  148. })
  149. })
  150. },
  151. //手机号登录
  152. PhoneLogin({ commit }, userInfo) {
  153. return new Promise((resolve, reject) => {
  154. api.phoneNoLogin(userInfo).then(response => {
  155. if(response.code =='200'){
  156. const result = response.result
  157. const userInfo = result.userInfo
  158. commit('SET_TOKEN', result.token)
  159. commit('SET_NAME', { username: userInfo.username,realname: userInfo.realname})
  160. commit('SET_AVATAR', userInfo.avatar)
  161. resolve(response)
  162. }else{
  163. reject(response)
  164. }
  165. }).catch(error => {
  166. reject(error)
  167. })
  168. })
  169. },
  170. // 登出
  171. Logout({ commit, state }) {
  172. return new Promise((resolve) => {
  173. let logoutToken = state.token;
  174. /* commit('SET_TOKEN', '')
  175. commit('SET_SESSIONID', '')
  176. uni.removeStorageSync(ACCESS_TOKEN) */
  177. api.logout(logoutToken).then(() => {
  178. commit('SET_TOKEN', '');
  179. //uni.removeStorageSync(ACCESS_TOKEN);
  180. resolve()
  181. }).catch(() => {
  182. resolve()
  183. })
  184. })
  185. },
  186. },
  187. getters:{
  188. token: state => state.token,
  189. sessionId: state => state.sessionId,
  190. username: state => {state.username=uni.getStorageSync(USER_INFO).username; return state.username},
  191. realname: state => {state.realname=uni.getStorageSync(USER_INFO).realname; return state.realname},
  192. nickname: state => {state.userid=uni.getStorageSync(USER_INFO).realname; return state.user.realname},
  193. userid:state => state.userid,
  194. orgCode:state => {state.orgCode=uni.getStorageSync(USER_INFO).orgCode; return state.orgCode},
  195. id:state =>state.id,
  196. date:state => state.date,
  197. departId:state => state.departId,
  198. teamUserId:state => state.teamUserId,
  199. tmsUserId:state => state.tmsUserId,
  200. wagesDate:state => state.wagesDate,
  201. wagesId:state =>state.wagesId,
  202. rzdate:state =>state.rzdate,
  203. birthdate:state =>state.birthdate,
  204. emilCode:state =>state.emilCode,
  205. avatar:state => state.avatar,
  206. indexId:state => state.indexId,
  207. user:state=>state.user,
  208. chatname:state=>state.chatname,
  209. chatid:state=>state.chatid,
  210. perssion:state=>state.perssion,
  211. leave:state=>state.leave,
  212. status:state=>state.status
  213. },
  214. })