index.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. import login from '@/apis/login'
  4. import order from '@/apis/order'
  5. import user from '@/apis/user'
  6. import common from '@/apis/common'
  7. import tools from '@/common/tools'
  8. import axios from 'axios'
  9. Vue.use(Vuex);
  10. export default new Vuex.Store({
  11. //所有的数据都放在state中
  12. state: {
  13. TENANT_NANE: "",
  14. msgCount: 0,
  15. cartCount: 0,
  16. applyData: {}, //预约考试数据存放
  17. currentRouter: {},
  18. token: '',
  19. user_account: '',
  20. userInfo: null,
  21. examResult: {},
  22. dictList: {},//字典数据
  23. sysTime: 0,
  24. businessItem: null,
  25. educationType: null,
  26. businessList_t: null,
  27. businessList: [],
  28. packPageStatus: true,
  29. isDesktop: !navigator.userAgent.match(
  30. /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|IEMobile)/i
  31. ),
  32. //--------------------------------
  33. header: {},//页头配置
  34. footer: {},//页尾配置
  35. nav: [],//底部说明
  36. links: [],//友情链接
  37. consultPc: {},//移动端设置
  38. consultMobile: {},//移动端设置
  39. other: {},//移动端设置
  40. //--------------------------------
  41. },
  42. getters: {
  43. educationType(state) {
  44. if (!state.educationType) {
  45. common.educationTypeList({ status: 1 }).then(res => {
  46. state.educationType = res.rows
  47. })
  48. }
  49. return state.educationType
  50. },
  51. businessList_t(state) {
  52. if (!state.businessList_t) {
  53. common.businessList({ status: 1 }).then(res => {
  54. state.businessList_t = res.rows
  55. })
  56. }
  57. return state.businessList_t
  58. },
  59. businessList: state => state.businessList,
  60. businessItem: state => state.businessItem,
  61. sysTime: state => state.sysTime,
  62. userInfo: state => state.userInfo,
  63. token: state => state.token,
  64. header: state => state.header,
  65. footer: state => state.footer,
  66. nav: state => state.nav,
  67. links: state => state.links,
  68. consultPc: state => state.consultPc,
  69. other: state => state.other,
  70. getApplyData: state => state.applyData,
  71. examResult: state => state.examResult,
  72. currentRouter: state => state.currentRouter,
  73. cartCount: state => state.cartCount,
  74. msgCount: state => state.msgCount
  75. },
  76. //操作数据,唯一的通道是mutations
  77. mutations: {
  78. setDictList(state, data) {
  79. state.dictList = data;
  80. },
  81. setTENANT_NANE(state, id) {
  82. state.TENANT_NANE = id
  83. },
  84. setBusinessList(state, list) {
  85. state.businessList = list
  86. },
  87. setBusinessItem(state, item) {
  88. state.businessItem = item
  89. },
  90. commonSystemTime(state, time) {
  91. state.sysTime = time;
  92. },
  93. setCurrentRouter(state, data) {
  94. state.currentRouter = data;
  95. },
  96. setExamResult(state, data) {
  97. state.examResult = data;
  98. },
  99. updateApplyData(state, data) {
  100. state.applyData = data;
  101. },
  102. setUserInfo(state, data) {
  103. state.userInfo = data;
  104. },
  105. setHomeSetList(state, data) {
  106. console.log(data,'data')
  107. data.forEach(item => {
  108. // if (item.configKey === 'home.header') {
  109. // state.header = JSON.parse(item.configValue)
  110. // }
  111. // if (item.configKey === 'home.footer') {
  112. // state.footer = JSON.parse(item.configValue)
  113. // }
  114. // if (item.configKey === 'home.footer.record') {
  115. // state.footerRecord = JSON.parse(item.configValue) || {}
  116. // }
  117. // if (item.configKey === 'home.links') {
  118. // state.links = JSON.parse(item.configValue)
  119. // }
  120. // if (item.configKey === 'home.mobile') {
  121. // state.mobile = JSON.parse(item.configValue)
  122. // }
  123. if (item.configKey === 'client.config') {
  124. let configValue = JSON.parse(item.configValue) || {}
  125. for(let k in configValue){
  126. state[k] = configValue[k]
  127. console.log(k,configValue[k],'k')
  128. }
  129. }
  130. })
  131. },
  132. getCartCount(state) {
  133. user.cartList().then((res) => {
  134. state.cartCount = res.total;
  135. });
  136. },
  137. getMsgCount(state) {
  138. user.appinformUsercount({
  139. systemStatusList: '1,2',
  140. receiptStatus: 0,
  141. }).then(res => {
  142. state.msgCount = res.data
  143. })
  144. }
  145. },
  146. //actions,可以来做异步操作,然后提交给mutations,而后再对state(数据)进行操作
  147. actions: {
  148. findTenantId({
  149. commit
  150. }) {
  151. return new Promise(resolve => {
  152. var urlReg = /[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+\.?/;
  153. var urls = location.origin.includes("localhost") ? '' : urlReg.exec(location.origin)[0];
  154. if (location.origin.includes("192.168.1") || location.origin.includes("localhost") || location.origin.includes("120.79.166.78")) {
  155. urls = "120.79.166.78:19012"
  156. }
  157. axios.get(process.env.BASE_URL + '/app/common/findTenantId?hostPc=' + urls)
  158. .then(function (response) {
  159. let favicon = document.querySelector('link[rel="icon"]')
  160. favicon = document.createElement('link')
  161. favicon.rel = 'icon'
  162. favicon.href = response.data.data == '867735392558919680' ? '/static/favicon.ico' : '/static/favicons.ico'
  163. document.head.appendChild(favicon)
  164. commit('setTENANT_NANE', response.data.data)
  165. resolve()
  166. })
  167. .catch(function (error) {
  168. console.log("TenantIDerror:", error);
  169. });
  170. })
  171. },
  172. /**
  173. * 设置系统时间
  174. */
  175. setSystemTime({
  176. commit
  177. }) {
  178. return new Promise(resolve => {
  179. common.commonSystemTime().then(res => {
  180. if (res.code == 200) {
  181. commit('commonSystemTime', res.data)
  182. resolve()
  183. }
  184. })
  185. })
  186. },
  187. getbusinessList({
  188. commit
  189. }) {
  190. return new Promise(resolve => {
  191. order.orderUserAllBusinessList().then(res => {
  192. if (res.code == 200) {
  193. commit('setBusinessList', res.rows)
  194. if (res.rows && res.rows.length) {
  195. commit('setBusinessItem', res.rows[0])
  196. }
  197. resolve()
  198. }
  199. })
  200. })
  201. },
  202. /**
  203. *
  204. * @param {*} context
  205. * @returns
  206. * 获取用户信息
  207. */
  208. getUserInfo(context) {
  209. return new Promise(resolve => {
  210. login.getInfo({ fromPlat: 2 }).then(res => {
  211. context.commit('setUserInfo', res.data)
  212. if (!tools.getUuid()) {
  213. tools.setUuid(new Date().valueOf() + "")
  214. }
  215. resolve()
  216. }).catch(err => { })
  217. })
  218. },
  219. /**
  220. *
  221. * @param {*} context
  222. * @returns
  223. * 获取首页配置
  224. */
  225. getCommonBaseHomeList(context) {
  226. return new Promise(resolve => {
  227. common.getCommonBaseHomeList().then(res => {
  228. context.commit('setHomeSetList', res.rows)
  229. resolve()
  230. })
  231. })
  232. },
  233. /**
  234. *
  235. * @param {*} context
  236. * @returns
  237. * 获取字典配置
  238. */
  239. getCommonBaseDictList(context) {
  240. return new Promise(resolve => {
  241. common.dictList({status:1}).then(res => {
  242. if (res.code === 200) {
  243. let dictList = {};
  244. let list = res.data;
  245. for (let i = 0; i < list.length; i++) {
  246. let item = list[i];
  247. if (dictList.hasOwnProperty(item.dictType)) {
  248. dictList[item.dictType].push(item.dictLabel);
  249. } else {
  250. dictList[item.dictType] = [item.dictLabel];
  251. }
  252. }
  253. context.commit('setDictList', dictList)
  254. resolve()
  255. }
  256. })
  257. })
  258. },
  259. }
  260. })