123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445 |
- import { modifyAdminInfo, verifyToken } from '@/api/login/login'
- // import { mapGetters } from 'vuex'
- // import { getToken, setToken, removeToken } from '@/utils/auth'
- import { cacheAdminUserInfo, getAdminUserInfoCache, removeAdminUserInfoCache } from '@/utils/admin_info_cache'
- import { getFiledConfigList, setFiledConfigList } from '@/utils/data_config' // getConfigList from sessionStorage
-
- const xt_user = {
- state: {
- org_id: 0,
- schedule_type_selected: 0,
- zone_selected: 0,
- app_id: 0,
- user: {
- id: 0,
- mobile: '',
- avatar: '',
- user_name: '',
- intro: '',
- user_type: 0, // 用户类型(1.管理员;2.医生;3.护士;4.运营)
- user_title: 0 // 用户职称(1.医士;2.医师;3.住院医师;4.主治医师;5.副主任医师;6.主任医师;7.护士;8.护师;9.主管护师;10.副主任护师;11.主任护师;12.运营专员;13.运营主管)
- },
- template_info: {
- id: 0,
- org_id: 0,
- template_id: 0
- },
-
- org: {
- id: 0,
- org_name: '',
- org_short_name: '',
- org_intro: '',
- org_logo: '',
- province: 0,
- city: 0,
- district: 0,
- address: ''
- },
- subscibe: {
- id: 0,
- period_start: 0,
- period_end: 0,
- state: 2, // 1正版(标准) 2试用(免费) 3过期(或其他无效状态) 8 专业 9 永久,
- patients: 20 // 患者数
- },
-
- scrm_role_exist: false,
- cdm_role_exist: false,
- mall_role_exist: false,
-
- // 示例: ['', '',]
- urlfors: [],
- fileds: []
- },
-
- mutations: {
- SET_SCHEDULE_TYPE_SELECTED: (state, schedule_type_selected) => {
- state.schedule_type_selected = schedule_type_selected
- },
- SET_ZONE_SELECTED: (state, zone_selected) => {
- state.zone_selected = zone_selected
- },
- SET_FILEDS_LIST: (state, configlist) => {
- state.fileds = configlist
- },
- // cur_info: { user, cur_org_id, cur_app_id }
- SET_CURRENT_INFO: (state, cur_info) => {
- state.user.id = cur_info.user.id
- state.user.mobile = cur_info.user.mobile
- state.user.avatar = cur_info.user.avatar
- state.user.user_name = cur_info.user.user_name
- state.user.intro = cur_info.user.intro
- state.user.user_type = cur_info.user.user_type
- state.user.user_title = cur_info.user.user_title
-
- state.org_id = cur_info.cur_org_id
- state.app_id = cur_info.cur_app_id
-
- state.org.id = cur_info.org.id
- state.org.org_name = cur_info.org.org_name
- state.org.org_short_name = cur_info.org.org_short_name
- state.org.org_logo = cur_info.org.org_logo
- state.org.org_intro = cur_info.org.org_intro
- state.org.province = cur_info.org.province
- state.org.city = cur_info.org.city
- state.org.district = cur_info.org.district
- state.org.address = cur_info.org.address
-
- state.subscibe.id = cur_info.subscibe.id
- state.subscibe.period_start = cur_info.subscibe.period_start
- state.subscibe.period_end = cur_info.subscibe.period_end
- state.subscibe.state = cur_info.subscibe.state
-
- state.scrm_role_exist = cur_info.scrm_role_exist
- state.cdm_role_exist = cur_info.cdm_role_exist
- state.mall_role_exist = cur_info.mall_role_exist
-
- state.template_info.id = cur_info.template_info.id
- state.template_info.org_id = cur_info.template_info.org_id
- state.template_info.template_id = cur_info.template_info.template_id
-
- },
-
- SET_FILEDS: (state, payload) => {
- state.fileds = payload.fileds
- },
-
- SET_URLFORS: (state, payload) => {
- state.urlfors = payload.urlfors
- },
-
- MODIFY_USER_INFO: (state, payload) => {
- state.user.user_name = payload.user_name
- state.user.avatar = payload.avatar
- },
- MODIFY_ORG_INFO: (state, payload) => {
- state.org.org_name = payload.org_name
- state.org.org_short_name = payload.org_short_name
- },
-
- SET_SUBSCIBE_PATIENT: (state) => {
- state.subscibe.patients += 1
- },
- CLEAR_USER_INFO: (state) => {
- state.org_id = 0
- state.app_id = 0
-
- state.user.id = 0
- state.user.mobile = ''
- state.user.avatar = ''
- state.user.user_name = ''
- state.user.intro = ''
- state.user_type = ''
- state.user_title = ''
-
- state.org.id = 0
- state.org.org_name = ''
- state.org.org_short_name = ''
- state.org.org_logo = ''
- state.org.org_intro = ''
- state.org.province = 0
- state.org.city = 0
- state.org.district = 0
- state.org.address = ''
-
- state.subscibe.id = 0
- state.subscibe.period_start = 0
- state.subscibe.period_end = 0
- state.subscibe.state = 3
- state.subscibe.patients = 0
-
- state.scrm_role_exist = false
- state.cdm_role_exist = false
- state.mall_role_exist = false
-
- state.template_info.id = 0
- state.template_info.org_id = 0
- state.template_info.template_id = 1
-
- state.urlfors = []
- state.fileds = []
-
- }
- },
-
- getters: {
- current_role_urls: state => {
- return state.urlfors
- }
- },
-
- actions: {
- SetScheduleTypeSelected({ commit }, schedule_type_selected) {
- commit('SET_SCHEDULE_TYPE_SELECTED', schedule_type_selected)
- },
- SetZoneSelected({ commit }, zone_selected) {
- commit('SET_ZONE_SELECTED', zone_selected)
- },
- SetSubscibePatients({
- commit,
- state
- }) {
- commit('SET_SUBSCIBE_PATIENT')
- },
-
- VerifyToken({
- commit,
- state
- }, token) {
-
- // console.log('验证 token 之前:token = ' + token)
- return new Promise((resolve, reject) => {
- var cacheInfo = getAdminUserInfoCache()
- var fileds = getFiledConfigList()
- var infoJSON = JSON.parse(fileds)
- commit('SET_FILEDS', {
- fileds: infoJSON
-
- })
-
- // console.log('登录信息缓存:', cacheInfo)
- if (cacheInfo != null && cacheInfo.length > 0) {
- var infoJSON = JSON.parse(cacheInfo)
- // console.log('用户信息缓存:', infoJSON)
- commit('SET_CURRENT_INFO', {
- user: infoJSON.user,
- cur_org_id: infoJSON.current_org_id,
- cur_app_id: infoJSON.current_app_id,
- org: infoJSON.org,
- subscibe: infoJSON.subscibe,
- template_info: infoJSON.template_info,
- scrm_role_exist: infoJSON.scrm_role_exist,
- cdm_role_exist: infoJSON.cdm_role_exist,
- mall_role_exist: infoJSON.mall_role_exist
- })
-
-
- let urlfors = infoJSON.urlfors
- if(infoJSON.cdm_role_exist == true){
- console.log("有")
- urlfors.push("/slow")
- this.commit('SET_URLFORS', {
- urlfors: urlfors
- })
- }else{
- this.commit('SET_URLFORS', {
- urlfors: infoJSON.urlfors
- })
- }
-
- if(infoJSON.scrm_role_exist == true){
- urlfors.push("/scrm")
- this.commit('SET_URLFORS', {
- urlfors: urlfors
- })
- }else{
- this.commit('SET_URLFORS', {
- urlfors: infoJSON.urlfors
- })
- }
-
- if(infoJSON.mall_role_exist == true){
- console.log("有")
- urlfors.push("/shop")
- this.commit('SET_URLFORS', {
- urlfors: urlfors
- })
- }else{
- this.commit('SET_URLFORS', {
- urlfors: infoJSON.urlfors
- })
- }
- console.log(222222222222,infoJSON)
-
- // commit('SET_URLFORS', {
- // urlfors: infoJSON.urlfors
- // })
-
- resolve(infoJSON.user.user_id)
- } else {
- verifyToken(token).then(response => {
- if (response.data.state === 1) {
- // alert('验证通过')
- // console.log('验证通过')
- var data = response.data.data
- this.commit('SET_CURRENT_INFO', {
- user: data.user,
- cur_org_id: data.current_org_id,
- cur_app_id: data.current_app_id,
- org: data.org,
- subscibe: data.subscibe,
- template_info: data.template_info,
- scrm_role_exist: data.scrm_role_exist,
- cdm_role_exist: data.cdm_role_exist,
- mall_role_exist: data.mall_role_exist
- })
-
- let urlfors = data.urlfors
- if(data.cdm_role_exist == true){
- console.log("有")
- urlfors.push("/slow")
- this.commit('SET_URLFORS', {
- urlfors: urlfors
- })
- }else{
- this.commit('SET_URLFORS', {
- urlfors: data.urlfors
- })
- }
-
- if(data.scrm_role_exist == true){
- urlfors.push("/scrm")
- this.commit('SET_URLFORS', {
- urlfors: urlfors
- })
- }else{
- this.commit('SET_URLFORS', {
- urlfors: data.urlfors
- })
- }
-
- if(data.mall_role_exist == true){
- console.log("有")
- urlfors.push("/shop")
- this.commit('SET_URLFORS', {
- urlfors: urlfors
- })
- }else{
- this.commit('SET_URLFORS', {
- urlfors: data.urlfors
- })
- }
-
-
- // this.commit('SET_URLFORS', {
- // urlfors: data.urlfors
- // })
-
- commit('SET_FILEDS', {
- fileds: data.fileds
- })
- setFiledConfigList(JSON.stringify(data.fileds))
- cacheAdminUserInfo(JSON.stringify(data))
-
- resolve(data.user.id)
- } else {
- alert('请求失败:' + response.data.msg)
- reject({
- msg: response.data.msg,
- code: response.data.code
- })
- }
- })
- }
- })
- },
- ModifyAdminUserInfo({
- commit,
- state
- }, params) {
- commit('MODIFY_USER_INFO', {
- user_name: params.user_name,
- avatar: params.avatar
- })
- cacheAdminUserInfo(
- JSON.stringify({
- user: state.user,
- org: state.org,
- current_org_id: state.org_id,
- current_app_id: state.app_id,
- urlfors: state.urlfors,
- subscibe: state.subscibe,
- template_info: state.template_info,
- scrm_role_exist: state.scrm_role_exist,
- cdm_role_exist: state.cdm_role_exist,
- mall_role_exist: state.mall_role_exist
- })
- )
- },
- ModifyOrgInfo({
- commit,
- state
- }, params) {
- commit('MODIFY_ORG_INFO', {
- org_name: params.org_name,
- org_short_name: params.org_short_name
- })
- cacheAdminUserInfo(
- JSON.stringify({
- user: state.user,
- org: state.org,
- current_org_id: state.org_id,
- current_app_id: state.app_id,
- urlfors: state.urlfors,
- subscibe: state.subscibe,
- template_info: state.template_info,
- scrm_role_exist: state.scrm_role_exist,
- cdm_role_exist: state.cdm_role_exist,
- mall_role_exist: state.mall_role_exist
- })
- )
- },
-
- // InitAdminUserInfo( {commit, state} ) {
- // var cacheInfo = getAdminUserInfoCache()
- // console.log("登录信息缓存:", cacheInfo)
- // if (cacheInfo != null && cacheInfo.length > 0) {
- // var infoJSON = JSON.parse(cacheInfo)
- // console.log(infoJSON)
- // commit('SET_CURRENT_INFO', {
- // user: infoJSON.user,
- // cur_org_id: infoJSON.current_org_id,
- // cur_app_id: infoJSON.current_app_id,
- // org: infoJSON.org,
- // })
-
- // commit('SET_URLFORS', {
- // urlfors: infoJSON.urlfors
- // })
- // }
- // }
- // 登出
- FrontendLogout({
- commit
- }) {
- commit('CLEAR_USER_INFO')
- removeAdminUserInfoCache()
- }, updateFiledConfigList({ commit }, object) {
-
- var oldFiledList = getFiledConfigList()
- var infoJSON = JSON.parse(oldFiledList)
- console.log(object)
- return new Promise((resolve, reject) => {
- for (let i = 0; i < infoJSON.length; i++) {
- if (infoJSON[i].id == object.id) {
- infoJSON[i].is_show = object.is_show
- }
- }
-
- setFiledConfigList(JSON.stringify(infoJSON))
- commit('SET_FILEDS_LIST', infoJSON)
- resolve()
- })
- }, updateAllFiledConfigList({ commit }, object) {
- var oldFiledList = getFiledConfigList()
- var infoJSON = JSON.parse(oldFiledList)
-
- return new Promise((resolve, reject) => {
- infoJSON = object
- setFiledConfigList(JSON.stringify(infoJSON))
- commit('SET_FILEDS_LIST', infoJSON)
- resolve()
- })
- }, ModifyAdminUserOrgInfo({ commit, state }, obj) {
- this.commit('SET_CURRENT_INFO',obj)
- },ModifyUrlInfo({ commit, state }, obj) {
- this.commit('SET_URLFORS', obj)
- },ModifyFiled({ commit, state }, obj) {
- commit('SET_FILEDS', obj)
- }
- }
- }
-
- export default xt_user
|