feat:部门选择
This commit is contained in:
@@ -63,6 +63,7 @@ export default {
|
||||
method: 'GET',
|
||||
params
|
||||
}),
|
||||
|
||||
//调拨归还执行
|
||||
execGiveback: data =>
|
||||
request({
|
||||
|
||||
@@ -25,6 +25,11 @@ export const apiCrypto = {
|
||||
export const clientSecret = ' 2E1TFEkR8YaOcLhp'
|
||||
// 附件前缀
|
||||
export const attachmentKey = 'lims_attachment'
|
||||
// 公司部门重试请求头
|
||||
export const COMPANY_DEPT_RETRY_HEADER = '__companyDeptRetried'
|
||||
export const VISIT_COMPANY_STORAGE_KEY = 'visit-company-info'
|
||||
export const VISIT_DEPT_STORAGE_KEY = 'visit-dept-info'
|
||||
|
||||
export default {
|
||||
apiPath,
|
||||
apiCrypto,
|
||||
|
||||
@@ -7,6 +7,7 @@ import Request from 'luch-request'
|
||||
import { getBaseUrl, getTenantId } from '@/defaultBaseUrl'
|
||||
import $store from '@/nx/store'
|
||||
import qs from 'qs'
|
||||
import { COMPANY_DEPT_RETRY_HEADER, VISIT_COMPANY_STORAGE_KEY, VISIT_DEPT_STORAGE_KEY } from '@/nx/config'
|
||||
|
||||
const options = {
|
||||
// 显示操作成功消息 默认不显示
|
||||
@@ -27,9 +28,6 @@ const options = {
|
||||
isTransformResponse: true
|
||||
}
|
||||
|
||||
const COMPANY_DEPT_RETRY_HEADER = '__companyDeptRetried'
|
||||
const VISIT_COMPANY_STORAGE_KEY = 'visit-company-info'
|
||||
const VISIT_DEPT_STORAGE_KEY = 'visit-dept-info'
|
||||
// Loading全局实例
|
||||
let LoadingInstance = {
|
||||
target: null,
|
||||
@@ -99,27 +97,19 @@ http.interceptors.request.use(
|
||||
config.header['Pragma'] = 'no-cache'
|
||||
}
|
||||
|
||||
let params = config.params || {}
|
||||
let data = config.data || false
|
||||
// if (process.env.NODE_ENV == 'development') console.log('development--params', params)
|
||||
// if (process.env.NODE_ENV == 'development') console.log('development--data', data)
|
||||
|
||||
// const visitCompanyId = getVisitCompanyId()
|
||||
const visitCompanyId = '101'
|
||||
const visitCompanyId = getVisitCompanyId()
|
||||
if (visitCompanyId !== undefined && visitCompanyId !== null && visitCompanyId !== '') {
|
||||
config.header['visit-company-id'] = visitCompanyId
|
||||
// const visitCompanyName = getVisitCompanyName()
|
||||
const visitCompanyName = '"深圳总公司'
|
||||
const visitCompanyName = getVisitCompanyName()
|
||||
if (visitCompanyName !== undefined && visitCompanyName !== null) {
|
||||
config.header['visit-company-name'] = encodeURIComponent(visitCompanyName || '')
|
||||
}
|
||||
}
|
||||
// const visitDeptId = getVisitDeptId()
|
||||
const visitDeptId = '103'
|
||||
const visitDeptId = getVisitDeptId()
|
||||
if (visitDeptId !== undefined && visitDeptId !== null && visitDeptId !== '') {
|
||||
config.header['visit-dept-id'] = visitDeptId
|
||||
// const visitDeptName = getVisitDeptName()
|
||||
const visitDeptName = '研发部门'
|
||||
const visitDeptName = getVisitDeptName()
|
||||
|
||||
if (visitDeptName !== undefined && visitDeptName !== null) {
|
||||
config.header['visit-dept-name'] = encodeURIComponent(visitDeptName || '')
|
||||
}
|
||||
@@ -153,7 +143,6 @@ http.interceptors.response.use(
|
||||
|
||||
// 统一处理【公司/部门二次选择】:参考 PC 端逻辑,自动补全或提示选择后重试
|
||||
if (code === 400 && Array.isArray(data)) {
|
||||
debugger
|
||||
const companyDeptList = data
|
||||
const config = response.config
|
||||
config.header = config.header || {}
|
||||
@@ -161,7 +150,7 @@ http.interceptors.response.use(
|
||||
const item = companyDeptList[0]
|
||||
if (!config.header[COMPANY_DEPT_RETRY_HEADER]) {
|
||||
applyCompanyDeptSelection(item, config)
|
||||
return request(config)
|
||||
return http.request(config)
|
||||
}
|
||||
uni.showToast({
|
||||
title: '公司/部门信息缺失,且自动补全失败,请联系管理员',
|
||||
@@ -187,7 +176,7 @@ http.interceptors.response.use(
|
||||
},
|
||||
config
|
||||
)
|
||||
resolve(request(config))
|
||||
resolve(http.request(config))
|
||||
},
|
||||
onCancel: () => {
|
||||
uni.showToast({
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
const defaultState = () => ({
|
||||
show: false,
|
||||
@@ -7,60 +7,69 @@ const defaultState = () => ({
|
||||
selectedCompanyId: null,
|
||||
selectedDeptId: null,
|
||||
onConfirm: null,
|
||||
onCancel: null,
|
||||
});
|
||||
onCancel: null
|
||||
})
|
||||
|
||||
const companyDeptStore = defineStore({
|
||||
id: 'company-dept',
|
||||
state: defaultState,
|
||||
actions: {
|
||||
open({ companyList = [], onConfirm = null, onCancel = null, defaultCompanyId = null, defaultDeptId = null, title = null }) {
|
||||
this.companyList = companyList;
|
||||
this.onConfirm = onConfirm;
|
||||
this.onCancel = onCancel;
|
||||
this.title = title || '请选择当前业务办理归属的公司部门信息';
|
||||
this.show = true;
|
||||
this.selectedCompanyId = defaultCompanyId;
|
||||
this.selectedDeptId = defaultDeptId;
|
||||
open({
|
||||
companyList = [],
|
||||
onConfirm = null,
|
||||
onCancel = null,
|
||||
defaultCompanyId = null,
|
||||
defaultDeptId = null,
|
||||
title = null
|
||||
}) {
|
||||
this.companyList = companyList
|
||||
this.onConfirm = onConfirm
|
||||
this.onCancel = onCancel
|
||||
this.title = title || '请选择当前业务办理归属的公司部门信息'
|
||||
this.show = true
|
||||
this.selectedCompanyId = defaultCompanyId
|
||||
this.selectedDeptId = defaultDeptId
|
||||
if (!this.selectedCompanyId && this.companyList.length > 0) {
|
||||
this.selectedCompanyId = this.companyList[0].companyId;
|
||||
this.selectedCompanyId = this.companyList[0].companyId
|
||||
}
|
||||
if (!this.selectedDeptId) {
|
||||
const depts = this.getDeptsByCompanyId(this.selectedCompanyId);
|
||||
this.selectedDeptId = depts.length > 0 ? depts[0].deptId : null;
|
||||
const depts = this.getDeptsByCompanyId(this.selectedCompanyId)
|
||||
this.selectedDeptId = depts.length > 0 ? depts[0].deptId : null
|
||||
}
|
||||
},
|
||||
close() {
|
||||
Object.assign(this, defaultState());
|
||||
this.show = false
|
||||
},
|
||||
getDeptsByCompanyId(companyId) {
|
||||
const company = this.companyList.find((item) => item.companyId === companyId);
|
||||
return company?.depts || [];
|
||||
const company = this.companyList.find(item => item.companyId === companyId)
|
||||
return company?.depts || []
|
||||
},
|
||||
setSelectedCompany(companyId) {
|
||||
this.selectedCompanyId = companyId;
|
||||
const depts = this.getDeptsByCompanyId(companyId);
|
||||
const currentDeptIds = depts.map((dept) => dept.deptId);
|
||||
console.log(companyId)
|
||||
|
||||
this.selectedCompanyId = companyId
|
||||
const depts = this.getDeptsByCompanyId(companyId)
|
||||
const currentDeptIds = depts.map(dept => dept.deptId)
|
||||
if (!currentDeptIds.includes(this.selectedDeptId)) {
|
||||
this.selectedDeptId = depts.length > 0 ? depts[0].deptId : null;
|
||||
this.selectedDeptId = depts.length > 0 ? depts[0].deptId : null
|
||||
}
|
||||
},
|
||||
setSelectedDept(deptId) {
|
||||
this.selectedDeptId = deptId;
|
||||
this.selectedDeptId = deptId
|
||||
},
|
||||
confirm() {
|
||||
if (this.onConfirm) {
|
||||
this.onConfirm({ companyId: this.selectedCompanyId, deptId: this.selectedDeptId });
|
||||
this.onConfirm({ companyId: this.selectedCompanyId, deptId: this.selectedDeptId })
|
||||
}
|
||||
this.close();
|
||||
this.close()
|
||||
},
|
||||
cancel() {
|
||||
if (this.onCancel) {
|
||||
this.onCancel();
|
||||
this.onCancel()
|
||||
}
|
||||
this.close();
|
||||
},
|
||||
},
|
||||
});
|
||||
this.close()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
export default companyDeptStore;
|
||||
export default companyDeptStore
|
||||
|
||||
@@ -3,6 +3,7 @@ import userApi from '@/nx/api/user'
|
||||
import { getSysParameterBizByName } from '@/nx/api/sys'
|
||||
import md5 from 'md5'
|
||||
import nx from '@/nx'
|
||||
import { COMPANY_DEPT_RETRY_HEADER, VISIT_COMPANY_STORAGE_KEY, VISIT_DEPT_STORAGE_KEY } from '@/nx/config'
|
||||
// 默认用户信息
|
||||
const defaultUserInfo = {
|
||||
avatar: '', // 头像
|
||||
@@ -128,6 +129,10 @@ const user = defineStore({
|
||||
this.roleMenus = []
|
||||
uni.setStorageSync('roleMenus', [])
|
||||
this.setToken()
|
||||
// 清空部门信息
|
||||
uni.removeStorageSync(COMPANY_DEPT_RETRY_HEADER)
|
||||
uni.removeStorageSync(VISIT_COMPANY_STORAGE_KEY)
|
||||
uni.removeStorageSync(VISIT_DEPT_STORAGE_KEY)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user