base.js 5.0 KB

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