base.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. import { defineStore } from 'pinia'
  2. import { message, theme } from 'ant-design-vue';
  3. import router from '@/router/index';
  4. import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
  5. import { createVNode } from 'vue';
  6. import { Modal } from 'ant-design-vue';
  7. import { useRouter } from "vue-router";
  8. import Api from '@/api/api'
  9. // 第一个参数是应用程序中 store 的唯一 id
  10. export const useBaseStore = defineStore('base', {
  11. state: () => {
  12. return {
  13. router: useRouter(),
  14. classAct:null, // 当前商品营销分类
  15. Provinces:[],
  16. tableRecord:[], // 记录表格勾选状态
  17. colMap:new Map(),
  18. fullscreen:false,
  19. siteInfo:{},
  20. themeAlgorithm:'defaultAlgorithm',
  21. canPointer:true, // 是否允许操作页面
  22. open:false,
  23. num:0,
  24. currentComponent:null, //抽屉详情路径
  25. connection:0, // 网络状态
  26. billChangeData:{},
  27. useloading:false,
  28. loading:false
  29. }
  30. },
  31. // 开启数据缓存
  32. persist: {
  33. enabled: true,
  34. strategies: [
  35. {
  36. storage: localStorage,
  37. paths: ['themeAlgorithm']
  38. }
  39. ]
  40. },
  41. getters:{},
  42. actions:{
  43. async siteData () {
  44. const res = await Api.requested({
  45. classname:'webmanage.site.site',
  46. method:'querySite',
  47. content:{}
  48. })
  49. this.siteInfo = res.data
  50. },
  51. /**
  52. * 获取系统省市县数据
  53. */
  54. async ProvincesData () {
  55. const res = await Api.requested({
  56. "classname": "system.tools",
  57. "method": "query_arealist",
  58. "content": {},
  59. })
  60. let node = res.data
  61. function createMenu(node) {
  62. let obj = Object.keys(node).map((key,index,item)=>{
  63. var elNode = {
  64. label: key,
  65. value: key,
  66. item:node[key],
  67. }
  68. return elNode;
  69. })
  70. obj.forEach(e=>{
  71. if ((e.item) instanceof Array) {
  72. e.children = []
  73. e.item.forEach(c=>{
  74. e.children.push({
  75. label:c,
  76. value:c
  77. })
  78. })
  79. } else {
  80. if (Object.keys(e.item).length !== 0) {
  81. e.children = createMenu(e.item)
  82. }
  83. }
  84. })
  85. return obj
  86. }
  87. return createMenu(res.data)
  88. },
  89. /**
  90. * 改变布局紧凑模式
  91. */
  92. changeLayout () {
  93. if (this.themeAlgorithm == 'defaultAlgorithm') {
  94. this.themeAlgorithm = 'compactAlgorithm'
  95. } else {
  96. this.themeAlgorithm = 'defaultAlgorithm'
  97. }
  98. },
  99. /**
  100. * 查询购物车计数
  101. */
  102. async shopCartNum (){
  103. const res = await Api.requested({
  104. id:20220927093202,
  105. content:{}
  106. })
  107. this.num = res.data.num
  108. },
  109. /**
  110. * 详情弹出抽屉
  111. */
  112. async openDrawerPage (routerName,id) {
  113. this.router.push({name:this.router.currentRoute.name,query:{id:id}})
  114. let routes = this.router.getRoutes()
  115. const rs = await routes.filter(e=>e.name == routerName)[0].components.default()
  116. this.currentComponent = rs.default
  117. this.open = !this.open
  118. },
  119. /**
  120. * 缓存单据改动后,不允许操作的接口
  121. */
  122. saveBillChangeData (data) {
  123. this.billChangeData = data
  124. },
  125. /**
  126. * 判断请求执行前是否有未保存的信息
  127. */
  128. checkNeedSaveData (config,axios) {
  129. let DATA = this.billChangeData
  130. const ndid = DATA.ndid
  131. if (DATA.editing && ndid.includes(config.data.id)) {
  132. let cancel;
  133. config.cancelToken = new axios.CancelToken((c) => {
  134. cancel = c;
  135. });
  136. cancel(`${config.url}请求被中断`);
  137. Modal.confirm({
  138. title: '提示',
  139. icon: createVNode(ExclamationCircleOutlined),
  140. content: '当前编辑数据未保存,是否保存?',
  141. okText: '保存',
  142. cancelText: '不保存',
  143. onOk() {
  144. console.log('OK');
  145. DATA.fn()
  146. },
  147. onCancel() {
  148. console.log('Cancel');
  149. },
  150. });
  151. } else {
  152. return true
  153. }
  154. },
  155. /**
  156. * 判断订单是否允许添加重复商品
  157. */
  158. addRepeatProd (data) {
  159. return new Promise(async (resolve, reject) => {
  160. const res = await Api.requested(data)
  161. if (!res.data.isrepeat && res.data.items.length > 0) {
  162. message.error(`${res.data.items.map(e=>e.itemname).join(',')}已存在,不允许添加重复商品!`)
  163. } else {
  164. if (res.data.items.length == 0) return resolve()
  165. Modal.confirm({
  166. title: '重复提示!',
  167. icon: createVNode(ExclamationCircleOutlined),
  168. okText:'确认添加',
  169. content: `${res.data.items.map(e=>e.itemname).join(',')}已存在,是否继续添加?`,
  170. onOk() {
  171. resolve()
  172. },
  173. onCancel() {
  174. console.log('Cancel');
  175. },
  176. class: 'test',
  177. });
  178. }
  179. })
  180. }
  181. }
  182. })