| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- import { defineStore } from 'pinia'
- import { message, theme } from 'ant-design-vue';
- import router from '@/router/index';
- import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
- import { createVNode } from 'vue';
- import { Modal } from 'ant-design-vue';
- import { useRouter } from "vue-router";
- import Api from '@/api/api'
- // 第一个参数是应用程序中 store 的唯一 id
- export const useBaseStore = defineStore('base', {
- state: () => {
- return {
- router: useRouter(),
- classAct:null, // 当前商品营销分类
- Provinces:[],
- tableRecord:[], // 记录表格勾选状态
- colMap:new Map(),
- fullscreen:false,
- siteInfo:{},
- themeAlgorithm:'defaultAlgorithm',
- canPointer:true, // 是否允许操作页面
- open:false,
- num:0,
- currentComponent:null, //抽屉详情路径
- connection:0, // 网络状态
- billChangeData:{},
- useloading:false,
- loading:false
- }
- },
- // 开启数据缓存
- persist: {
- enabled: true,
- strategies: [
- {
- storage: localStorage,
- paths: ['themeAlgorithm']
- }
- ]
- },
- getters:{},
- actions:{
- async siteData () {
- const res = await Api.requested({
- classname:'webmanage.site.site',
- method:'querySite',
- content:{}
- })
- this.siteInfo = res.data
- },
- /**
- * 获取系统省市县数据
- */
- async ProvincesData () {
- const res = await Api.requested({
- "classname": "system.tools",
- "method": "query_arealist",
- "content": {},
- })
- let node = res.data
- function createMenu(node) {
- let obj = Object.keys(node).map((key,index,item)=>{
- var elNode = {
- label: key,
- value: key,
- item:node[key],
- }
- return elNode;
- })
- obj.forEach(e=>{
- if ((e.item) instanceof Array) {
- e.children = []
- e.item.forEach(c=>{
- e.children.push({
- label:c,
- value:c
- })
- })
- } else {
- if (Object.keys(e.item).length !== 0) {
- e.children = createMenu(e.item)
- }
- }
- })
- return obj
- }
- return createMenu(res.data)
-
- },
- /**
- * 改变布局紧凑模式
- */
- changeLayout () {
- if (this.themeAlgorithm == 'defaultAlgorithm') {
- this.themeAlgorithm = 'compactAlgorithm'
- } else {
- this.themeAlgorithm = 'defaultAlgorithm'
- }
- },
- /**
- * 查询购物车计数
- */
- async shopCartNum (){
- const res = await Api.requested({
- id:20220927093202,
- content:{}
- })
- this.num = res.data.num
- },
- /**
- * 详情弹出抽屉
- */
- async openDrawerPage (routerName,id) {
- this.router.push({name:this.router.currentRoute.name,query:{id:id}})
- let routes = this.router.getRoutes()
- const rs = await routes.filter(e=>e.name == routerName)[0].components.default()
- this.currentComponent = rs.default
- this.open = !this.open
- },
- /**
- * 缓存单据改动后,不允许操作的接口
- */
- saveBillChangeData (data) {
- this.billChangeData = data
- },
- /**
- * 判断请求执行前是否有未保存的信息
- */
- checkNeedSaveData (config,axios) {
- let DATA = this.billChangeData
- const ndid = DATA.ndid
- if (DATA.editing && ndid.includes(config.data.id)) {
- let cancel;
- config.cancelToken = new axios.CancelToken((c) => {
- cancel = c;
- });
- cancel(`${config.url}请求被中断`);
- Modal.confirm({
- title: '提示',
- icon: createVNode(ExclamationCircleOutlined),
- content: '当前编辑数据未保存,是否保存?',
- okText: '保存',
- cancelText: '不保存',
- onOk() {
- console.log('OK');
- DATA.fn()
- },
- onCancel() {
- console.log('Cancel');
- },
- });
- } else {
- return true
- }
- },
- /**
- * 判断订单是否允许添加重复商品
- */
- addRepeatProd (data) {
- return new Promise(async (resolve, reject) => {
- const res = await Api.requested(data)
- if (!res.data.isrepeat && res.data.items.length > 0) {
- message.error(`${res.data.items.map(e=>e.itemname).join(',')}已存在,不允许添加重复商品!`)
- } else {
- if (res.data.items.length == 0) return resolve()
- Modal.confirm({
- title: '重复提示!',
- icon: createVNode(ExclamationCircleOutlined),
- okText:'确认添加',
- content: `${res.data.items.map(e=>e.itemname).join(',')}已存在,是否继续添加?`,
- onOk() {
- resolve()
- },
- onCancel() {
- console.log('Cancel');
- },
- class: 'test',
- });
- }
- })
- }
- }
- })
|