mutations.ts 10.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424
import { Environment } from '@/environments/environment';
import { MicroAppService } from '@/micro';
import { LogUtil, Util } from 'ibiz-core';

/**
 * 添加部门成员
 * 
 * @param state 
 * @param codelists 
 */
export const addDepartmentPersonnel = (state: any, departmentPersonnel: Array<any>) => {
    state.departmentPersonnel = [];
    state.departmentPersonnel = [...departmentPersonnel];
}

/**
 * 添加代码表
 * 
 * @param state 
 * @param codelists 
 */
export const addCodeLists = (state: any, codelists: any) => {
    state.codelists = [];
    state.codelists = [...codelists];
}

/**
 * 添加本地应用数据
 * 
 * @param state 
 * @param localdata 
 */
export const addLocalData = (state: any, localdata: any = {}) => {
    Object.assign(state.localdata, localdata);
    localStorage.setItem('localdata', JSON.stringify(state.localdata));
}

/**
 * 添加应用数据
 * 
 * @param state 
 * @param localdata 
 */
export const addAppData = (state: any, appdata: string) => {
    state.appdata = appdata;
}

/**
 * 修改应用数据
 * 
 * @param state 
 * @param localdata 
 */
export const updateAppData = (state: any, appdata: string) => {
    state.appdata = appdata;
}

/**
 * 更新代码表值
 * 
 * @param state 
 * @param param1 
 */
export const updateCodeList = (state: any, { srfkey, items }: { srfkey: string, items: any[] }) => {
    const index = state.codelists.findIndex((_codelist: any) => Object.is(_codelist.srfkey, srfkey));
    if (index === -1) {
        LogUtil.log(`${srfkey} ---- 代码表不存在`);
        return;
    }
    state.codelists[index].items = [...items];
}

/**
 * 修改主题
 * 
 * @param state 
 * @param val 
 */
export const setCurrentSelectTheme = (state: any, val: any) => {
    state.selectTheme = val;
}

/**
 * 修改字体
 * 
 * @param state 
 * @param val 
 */
export const setCurrentSelectFont = (state: any, val: any) => {
    state.selectFont = val;
}

/**
 * 重置分页导航数据
 * 
 * @param state 
 */
export const resetRootStateData = (state: any) => {
    state.pageTagList = [];
    state.pageMetas = [];
    state.historyPathList = [];
}

/**
 * 添加导航页面
 * 
 * @param state 
 * @param arg 
 */
export const addPage = (state: any, arg: any) => {
    if (!arg) {
        return;
    }
    // 视图类型为REDIRECTVIEW和NOTAB的视图不添加缓存
    if (Object.is(arg.meta.viewType, 'REDIRECTVIEW') || Object.is(arg.meta.viewType, 'NOTAB')) {
        return;
    } else if (Object.is(arg.meta.viewType, 'APPINDEX')) {
        window.sessionStorage.setItem(Environment.AppName, arg.fullPath);
    } else {
        const page: any = {};
        const pageMeta: any = {};
        Object.assign(page, arg);
        Object.assign(pageMeta, page.meta, { info: null, fullPath: arg.fullPath });
        const index = state.pageTagList.findIndex((tag: any) => Object.is(tag.fullPath, page.fullPath));
        if (index < 0) {
            state.pageTagList.push(page);
            state.pageMetas.push(pageMeta);
            const microAppService = MicroAppService.getInstance();
            if (microAppService && microAppService.getIsMicroApp()) {
                const data = Util.deepCopy(pageMeta);
                Object.assign(data, { microAppName: Environment.microAppName, fullPath: page.fullPath });
                microAppService.noticeBaseApp({ action: 'ADD_PAGE', data })
            }
        } else {
            const index2 = state.historyPathList.indexOf(page.fullPath);
            if (index2 >= 0) {
                state.historyPathList.splice(index2, 1);
            }
        }
        state.historyPathList.push(page.fullPath);
    }
}

/**
 * 删除导航页面
 * 
 * @param state 
 * @param arg 
 */
export const deletePage = (state: any, arg: any) => {
    let delPage: any = null;
    if (isNaN(arg)) {
        const index = state.pageTagList.findIndex((page: any) => Object.is(page.fullPath, arg));
        if (index >= 0) {
            delPage = state.pageTagList[index];
            state.pageTagList.splice(index, 1);
            state.pageMetas.splice(index, 1);
        }
    } else {
        delPage = state.pageTagList[arg];
        state.pageTagList.splice(arg, 1);
        state.pageMetas.splice(arg, 1);
    }
    const index = state.historyPathList.findIndex((path: any) => Object.is(path, delPage?.fullPath));
    if (index >= 0) {
        state.historyPathList.splice(index, 1);
    }
}

/**
 * 设置导航页面
 * 
 * @param state 
 * @param arg 
 */
export const setCurPage = (state: any, arg: any) => {
    let page: any = null;
    if (isNaN(arg)) {
        const index = state.pageTagList.findIndex((page: any) => Object.is(page.fullPath, arg));
        if (index >= 0) {
            page = state.pageTagList[index];
        }
    } else {
        page = state.pageTagList[arg];
    }
    if (page) {
        const index = state.historyPathList.findIndex((path: any) => Object.is(path, page.fullPath));
        if (index >= 0) {
            state.historyPathList.splice(index, 1);
            state.historyPathList.push(page.fullPath);
        }
    }
}

/**
 * 设置导航页面标题
 * 
 * @param state 
 * @param param1 
 */
export const setCurPageCaption = (state: any, { route, caption, captionTag, info, cacheRoutePath }: { route: any, caption: string | null, captionTag: string | null, info: string | null, cacheRoutePath: string | null  }) => {
    if (route) {
        const curRoutePath = cacheRoutePath ? cacheRoutePath : route.fullPath;
        const index = state.pageTagList.findIndex((page: any) => Object.is(page.fullPath, curRoutePath));
        if (index >= 0) {
            state.pageMetas[index].caption = caption;
            state.pageMetas[index].info = info;
            state.pageMetas[index].captionTag = captionTag;
            const microAppService = MicroAppService.getInstance();
            if (microAppService && microAppService.getIsMicroApp()) {
                const data = Util.deepCopy(state.pageMetas[index]);
                Object.assign(data, { microAppName: Environment.microAppName, fullPath: curRoutePath });
                microAppService.noticeBaseApp({ action: 'UPDATE_PAGE', data });
            }
        }
    }
}

/**
 * 添加当前视图视图标识
 * 
 * @param state 
 * @param param1 
 */
export const addCurPageViewtag = (state: any, { fullPath, viewtag }: { fullPath: string, viewtag: string }) => {
    const index = state.pageTagList.findIndex((page: any) => Object.is(page.fullPath, fullPath));
    if (index >= 0) {
        state.pageTagList[index].viewtag = viewtag;
    }
}

/**
 * 删除所有导航页面
 * 
 * @param state 
 */
export const removeAllPage = (state: any) => {
    if (state.pageTagList.length > 0) {
        state.pageMetas = [];
        state.pageTagList = [];
        state.historyPathList = [];
    }
}

/**
 * 删除其他导航页面
 * 
 * @param state 
 */
export const removeOtherPage = (state: any) => {
    if (state.historyPathList.length > 0) {
        const curPath = state.historyPathList[state.historyPathList.length - 1];
        const index = state.pageTagList.findIndex((page: any) => Object.is(page.fullPath, curPath));
        if (index >= 0) {
            const page = state.pageTagList[index];
            const meta: any = {};
            Object.assign(meta, page.meta);
            Object.assign(meta, { fullPath: page.fullPath });
            state.pageTagList = [];
            state.pageMetas = [];
            state.historyPathList = [];
            state.historyPathList.push(page.fullPath);
            state.pageTagList.push(page);
            state.pageMetas.push(meta);
        }
    }
}

/**
 * 更新 z-index 
 * 
 * @param state 
 * @param zIndex 
 */
export const updateZIndex = (state: any, zIndex: number) => {
    state.zIndex = zIndex;
}

/**
 * 设置视图split
 * 
 * @param state 
 * @param {viewSplit: number, viewUID: string} 
 */
export const setViewSplit = (state: any, args: { viewSplit: number, viewUID: string }) => {
    state.viewSplit[args.viewUID] = args.viewSplit;
}

/**
 * 添加单位数据
 * 
 * @param state 
 * @param args 
 */
export const addOrgData = (state: any, args: { srfkey: string, orgData: any }) => {
    if (args && args.srfkey && args.orgData) {
        state.orgDataMap[args.srfkey] = JSON.parse(JSON.stringify(args.orgData));
    }
}

/**
 * 添加部门数据
 * 
 * @param state 
 * @param args 
 */
export const addDepData = (state: any, args: { srfkey: string, depData: any }) => {
    if (args && args.srfkey && args.depData) {
        state.depDataMap[args.srfkey] = JSON.parse(JSON.stringify(args.depData));
    }
}

/**
 * 添加视图信息
 * 
 * @param state 
 * @param args 
 */
export const addViewMessage = (state: any, args: { tag: string, id: any }) => {
    if (args && args.tag && args.id) {
        state.viewMessage[args.tag] = args.id;
    }
}

/**
 * 添加自定义参数
 * 
 * @param state 
 * @param args 
 */
export const addCustomParam = (state: any, args: { tag: string, param: any }) => {
    if (args && args.tag && args.param) {
        state.customParam[args.tag] = args.param;
    }
}

/**
 * 删除指定键值自定义参数
 * 
 * @param state 
 * @param args 
 */
export const removeCustomParam = (state: any, tag: string) => {
    if (tag && state.customParam[tag]) {
        delete state.customParam[tag];
    }
}

/**
 * 添加全局数据
 * 
 * @param state 
 */
export const addAppGlobal = (state: any, args: { tag: string, param: any }) => {
    if (args && args.tag && args.param) {
        state.appGlobal[args.tag] = args.param;
    }
}

/**
 * 删除指定键值全局数据
 * 
 * @param state 
 * @param args 
 */
export const removeAppGlobal = (state: any, tag: string) => {
    if (tag && state.appGlobal[tag]) {
        delete state.appGlobal[tag];
    }
}

/**
 * 添加顶层路由数据参数
 * 
 * @param state 
 * @param args 
 */
export const addRouteViewGlobal = (state: any, args: { tag: string, param: any }) => {
    if (args && args.tag && args.param) {
        if(!state.routeViewGlobal[args.tag]){
            state.routeViewGlobal[args.tag] = args.param;
        }else{
            const cacheValue = state.routeViewGlobal[args.tag];
            Object.assign(cacheValue,args.param);
            state.routeViewGlobal[args.tag] = cacheValue;
        }
    }
}

/**
 * 删除指定键值顶层路由数据参数
 * 
 * @param state 
 * @param args 
 */
export const removeRouteViewGlobal = (state: any, tag: string) => {
    if (tag && state.routeViewGlobal[tag]) {
        delete state.routeViewGlobal[tag];
    }
}

/**
 * 添加顶层视图
 * 
 * @param state 
 * @param args 
 */
export const addView = (state: any, args: { tag: string, param: any }) => {
    if (args && args.tag && args.param) {
        state.appViews[args.tag] = args.param;
    }
}

/**
 * 删除顶层视图
 * 
 * @param state 
 * @param args 
 */
export const removeView = (state: any, tag: string) => {
    if (tag && state.appViews[tag]) {
        delete state.appViews[tag];
    }
}