index.js 6.7 KB

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