xt_user.js 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. import { modifyAdminInfo, verifyToken } from '@/api/login/login'
  2. // import { mapGetters } from 'vuex'
  3. // import { getToken, setToken, removeToken } from '@/utils/auth'
  4. import { cacheAdminUserInfo, getAdminUserInfoCache, removeAdminUserInfoCache } from '@/utils/admin_info_cache'
  5. import { getFiledConfigList, setFiledConfigList } from '@/utils/data_config' // getConfigList from sessionStorage
  6. const xt_user = {
  7. state: {
  8. org_id: 0,
  9. schedule_type_selected: 0,
  10. zone_selected: 0,
  11. app_id: 0,
  12. user: {
  13. id: 0,
  14. mobile: '',
  15. avatar: '',
  16. user_name: '',
  17. intro: '',
  18. user_type: 0, // 用户类型(1.管理员;2.医生;3.护士;4.运营)
  19. user_title: 0 // 用户职称(1.医士;2.医师;3.住院医师;4.主治医师;5.副主任医师;6.主任医师;7.护士;8.护师;9.主管护师;10.副主任护师;11.主任护师;12.运营专员;13.运营主管)
  20. },
  21. template_info: {
  22. id: 0,
  23. org_id: 0,
  24. template_id: 0
  25. },
  26. org: {
  27. id: 0,
  28. org_name: '',
  29. org_short_name: '',
  30. org_intro: '',
  31. org_logo: '',
  32. province: 0,
  33. city: 0,
  34. district: 0,
  35. address: ''
  36. },
  37. subscibe: {
  38. id: 0,
  39. period_start: 0,
  40. period_end: 0,
  41. state: 2, // 1正版(标准) 2试用(免费) 3过期(或其他无效状态) 8 专业 9 永久,
  42. patients: 20 // 患者数
  43. },
  44. scrm_role_exist: false,
  45. cdm_role_exist: false,
  46. mall_role_exist: false,
  47. // 示例: ['', '',]
  48. urlfors: [],
  49. fileds: []
  50. },
  51. mutations: {
  52. SET_SCHEDULE_TYPE_SELECTED: (state, schedule_type_selected) => {
  53. state.schedule_type_selected = schedule_type_selected
  54. },
  55. SET_ZONE_SELECTED: (state, zone_selected) => {
  56. state.zone_selected = zone_selected
  57. },
  58. SET_FILEDS_LIST: (state, configlist) => {
  59. state.fileds = configlist
  60. },
  61. // cur_info: { user, cur_org_id, cur_app_id }
  62. SET_CURRENT_INFO: (state, cur_info) => {
  63. state.user.id = cur_info.user.id
  64. state.user.mobile = cur_info.user.mobile
  65. state.user.avatar = cur_info.user.avatar
  66. state.user.user_name = cur_info.user.user_name
  67. state.user.intro = cur_info.user.intro
  68. state.user.user_type = cur_info.user.user_type
  69. state.user.user_title = cur_info.user.user_title
  70. state.org_id = cur_info.cur_org_id
  71. state.app_id = cur_info.cur_app_id
  72. state.org.id = cur_info.org.id
  73. state.org.org_name = cur_info.org.org_name
  74. state.org.org_short_name = cur_info.org.org_short_name
  75. state.org.org_logo = cur_info.org.org_logo
  76. state.org.org_intro = cur_info.org.org_intro
  77. state.org.province = cur_info.org.province
  78. state.org.city = cur_info.org.city
  79. state.org.district = cur_info.org.district
  80. state.org.address = cur_info.org.address
  81. state.subscibe.id = cur_info.subscibe.id
  82. state.subscibe.period_start = cur_info.subscibe.period_start
  83. state.subscibe.period_end = cur_info.subscibe.period_end
  84. state.subscibe.state = cur_info.subscibe.state
  85. state.scrm_role_exist = cur_info.scrm_role_exist
  86. state.cdm_role_exist = cur_info.cdm_role_exist
  87. state.mall_role_exist = cur_info.mall_role_exist
  88. state.template_info.id = cur_info.template_info.id
  89. state.template_info.org_id = cur_info.template_info.org_id
  90. state.template_info.template_id = cur_info.template_info.template_id
  91. },
  92. SET_FILEDS: (state, payload) => {
  93. state.fileds = payload.fileds
  94. },
  95. SET_URLFORS: (state, payload) => {
  96. state.urlfors = payload.urlfors
  97. },
  98. MODIFY_USER_INFO: (state, payload) => {
  99. state.user.user_name = payload.user_name
  100. state.user.avatar = payload.avatar
  101. },
  102. MODIFY_ORG_INFO: (state, payload) => {
  103. state.org.org_name = payload.org_name
  104. state.org.org_short_name = payload.org_short_name
  105. },
  106. SET_SUBSCIBE_PATIENT: (state) => {
  107. state.subscibe.patients += 1
  108. },
  109. CLEAR_USER_INFO: (state) => {
  110. state.org_id = 0
  111. state.app_id = 0
  112. state.user.id = 0
  113. state.user.mobile = ''
  114. state.user.avatar = ''
  115. state.user.user_name = ''
  116. state.user.intro = ''
  117. state.user_type = ''
  118. state.user_title = ''
  119. state.org.id = 0
  120. state.org.org_name = ''
  121. state.org.org_short_name = ''
  122. state.org.org_logo = ''
  123. state.org.org_intro = ''
  124. state.org.province = 0
  125. state.org.city = 0
  126. state.org.district = 0
  127. state.org.address = ''
  128. state.subscibe.id = 0
  129. state.subscibe.period_start = 0
  130. state.subscibe.period_end = 0
  131. state.subscibe.state = 3
  132. state.subscibe.patients = 0
  133. state.scrm_role_exist = false
  134. state.cdm_role_exist = false
  135. state.mall_role_exist = false
  136. state.template_info.id = 0
  137. state.template_info.org_id = 0
  138. state.template_info.template_id = 1
  139. state.urlfors = []
  140. state.fileds = []
  141. }
  142. },
  143. getters: {
  144. current_role_urls: state => {
  145. return state.urlfors
  146. }
  147. },
  148. actions: {
  149. SetScheduleTypeSelected({ commit }, schedule_type_selected) {
  150. commit('SET_SCHEDULE_TYPE_SELECTED', schedule_type_selected)
  151. },
  152. SetZoneSelected({ commit }, zone_selected) {
  153. commit('SET_ZONE_SELECTED', zone_selected)
  154. },
  155. SetSubscibePatients({
  156. commit,
  157. state
  158. }) {
  159. commit('SET_SUBSCIBE_PATIENT')
  160. },
  161. VerifyToken({
  162. commit,
  163. state
  164. }, token) {
  165. // console.log('验证 token 之前:token = ' + token)
  166. return new Promise((resolve, reject) => {
  167. var cacheInfo = getAdminUserInfoCache()
  168. var fileds = getFiledConfigList()
  169. var infoJSON = JSON.parse(fileds)
  170. commit('SET_FILEDS', {
  171. fileds: infoJSON
  172. })
  173. // console.log('登录信息缓存:', cacheInfo)
  174. verifyToken(token).then(response => {
  175. if (response.data.state === 1) {
  176. // alert('验证通过')
  177. // console.log('验证通过')
  178. var data = response.data.data
  179. this.commit('SET_CURRENT_INFO', {
  180. user: data.user,
  181. cur_org_id: data.current_org_id,
  182. cur_app_id: data.current_app_id,
  183. org: data.org,
  184. subscibe: data.subscibe,
  185. template_info: data.template_info,
  186. scrm_role_exist: data.scrm_role_exist,
  187. cdm_role_exist: data.cdm_role_exist,
  188. mall_role_exist: data.mall_role_exist
  189. })
  190. let urlfors = data.urlfors
  191. if(data.cdm_role_exist == true){
  192. console.log("有")
  193. urlfors.push("/slow")
  194. this.commit('SET_URLFORS', {
  195. urlfors: urlfors
  196. })
  197. }else{
  198. this.commit('SET_URLFORS', {
  199. urlfors: data.urlfors
  200. })
  201. }
  202. if(data.scrm_role_exist == true){
  203. urlfors.push("/scrm")
  204. this.commit('SET_URLFORS', {
  205. urlfors: urlfors
  206. })
  207. }else{
  208. this.commit('SET_URLFORS', {
  209. urlfors: data.urlfors
  210. })
  211. }
  212. if(data.mall_role_exist == true){
  213. console.log("有")
  214. urlfors.push("/shop")
  215. this.commit('SET_URLFORS', {
  216. urlfors: urlfors
  217. })
  218. }else{
  219. this.commit('SET_URLFORS', {
  220. urlfors: data.urlfors
  221. })
  222. }
  223. // this.commit('SET_URLFORS', {
  224. // urlfors: data.urlfors
  225. // })
  226. commit('SET_FILEDS', {
  227. fileds: data.fileds
  228. })
  229. setFiledConfigList(JSON.stringify(data.fileds))
  230. cacheAdminUserInfo(JSON.stringify(data))
  231. resolve(data.user.id)
  232. } else {
  233. alert('请求失败:' + response.data.msg)
  234. reject({
  235. msg: response.data.msg,
  236. code: response.data.code
  237. })
  238. }
  239. })
  240. })
  241. },
  242. ModifyAdminUserInfo({
  243. commit,
  244. state
  245. }, params) {
  246. commit('MODIFY_USER_INFO', {
  247. user_name: params.user_name,
  248. avatar: params.avatar
  249. })
  250. cacheAdminUserInfo(
  251. JSON.stringify({
  252. user: state.user,
  253. org: state.org,
  254. current_org_id: state.org_id,
  255. current_app_id: state.app_id,
  256. urlfors: state.urlfors,
  257. subscibe: state.subscibe,
  258. template_info: state.template_info,
  259. scrm_role_exist: state.scrm_role_exist,
  260. cdm_role_exist: state.cdm_role_exist,
  261. mall_role_exist: state.mall_role_exist
  262. })
  263. )
  264. },
  265. ModifyOrgInfo({
  266. commit,
  267. state
  268. }, params) {
  269. commit('MODIFY_ORG_INFO', {
  270. org_name: params.org_name,
  271. org_short_name: params.org_short_name
  272. })
  273. cacheAdminUserInfo(
  274. JSON.stringify({
  275. user: state.user,
  276. org: state.org,
  277. current_org_id: state.org_id,
  278. current_app_id: state.app_id,
  279. urlfors: state.urlfors,
  280. subscibe: state.subscibe,
  281. template_info: state.template_info,
  282. scrm_role_exist: state.scrm_role_exist,
  283. cdm_role_exist: state.cdm_role_exist,
  284. mall_role_exist: state.mall_role_exist
  285. })
  286. )
  287. },
  288. // InitAdminUserInfo( {commit, state} ) {
  289. // var cacheInfo = getAdminUserInfoCache()
  290. // console.log("登录信息缓存:", cacheInfo)
  291. // if (cacheInfo != null && cacheInfo.length > 0) {
  292. // var infoJSON = JSON.parse(cacheInfo)
  293. // console.log(infoJSON)
  294. // commit('SET_CURRENT_INFO', {
  295. // user: infoJSON.user,
  296. // cur_org_id: infoJSON.current_org_id,
  297. // cur_app_id: infoJSON.current_app_id,
  298. // org: infoJSON.org,
  299. // })
  300. // commit('SET_URLFORS', {
  301. // urlfors: infoJSON.urlfors
  302. // })
  303. // }
  304. // }
  305. // 登出
  306. FrontendLogout({
  307. commit
  308. }) {
  309. commit('CLEAR_USER_INFO')
  310. removeAdminUserInfoCache()
  311. }, updateFiledConfigList({ commit }, object) {
  312. var oldFiledList = getFiledConfigList()
  313. var infoJSON = JSON.parse(oldFiledList)
  314. console.log(object)
  315. return new Promise((resolve, reject) => {
  316. for (let i = 0; i < infoJSON.length; i++) {
  317. if (infoJSON[i].id == object.id) {
  318. infoJSON[i].is_show = object.is_show
  319. }
  320. }
  321. setFiledConfigList(JSON.stringify(infoJSON))
  322. commit('SET_FILEDS_LIST', infoJSON)
  323. resolve()
  324. })
  325. }, updateAllFiledConfigList({ commit }, object) {
  326. var oldFiledList = getFiledConfigList()
  327. var infoJSON = JSON.parse(oldFiledList)
  328. return new Promise((resolve, reject) => {
  329. infoJSON = object
  330. setFiledConfigList(JSON.stringify(infoJSON))
  331. commit('SET_FILEDS_LIST', infoJSON)
  332. resolve()
  333. })
  334. }, ModifyAdminUserOrgInfo({ commit, state }, obj) {
  335. this.commit('SET_CURRENT_INFO',obj)
  336. },ModifyUrlInfo({ commit, state }, obj) {
  337. this.commit('SET_URLFORS', obj)
  338. },ModifyFiled({ commit, state }, obj) {
  339. commit('SET_FILEDS', obj)
  340. }
  341. }
  342. }
  343. export default xt_user