UNPKG

ci-plus

Version:

ci组件库

177 lines (168 loc) 5.1 kB
import apis from './baseApi' import axios from 'axios' const { produceModule } = apis export interface User { user_code: string // 登录名:'148128' user_name: string // 用户名:'方卿' org_id: string // 公司ID:'1780861656362131456' org_name: string // 公司名称:'杭州人本轴承有限公司动力分厂' dept_id: string // 团队ID:'1712341581808545792' dept_name: string // 团队名称:'质控4团队' tenantId: string // 租户id:'1739466802218676224' } // 在pc端获取用户信息 const UserData = JSON.parse(localStorage.getItem('UserData') || '{}') let users = { org_id: UserData.orgId, org_name: UserData.orgName, user_code: UserData.loginName, user_name: UserData.name, dept_id: UserData.deptId, dept_name: UserData.deptName } let user = JSON.parse(JSON.stringify(users)) const cardPrintAxios = axios.create({ withCredentials: true }) cardPrintAxios.interceptors.request.use( (config) => { // if (userInfo.accessToken) // config.headers['Authorization'] = userInfo.accessToken if (config.method == 'get' && config.params) { Object.assign(config.params, user) } else if (config.method !== 'get') { if (config.data instanceof FormData) { let data: FormData = config.data Object.keys(user).forEach((k) => { if (!data.has(k)) data.append(k, user[k as keyof User]) }) } else Object.assign(config.data, user) } return config }, (error) => Promise.reject(error) ) interface AffiliationRES { id: string // 归属公司 id name: string // 归属公司 名称 parentId: string // 归属公司 父级id type: number // 归属公司 类型 del: string // 删除状态 createdId: string // 创建人id createdDate: string // 创建时间 orgCode: string // 归属公司 编码 treePath: string // 归属公司 路径 updatedId?: any // 修改人id updatedDate?: any // 修改时间 version?: any // 版本 sortNum?: any attribute?: any datasourceCode: string platform?: any platformTxt?: any sector?: any sectorTxt?: any area?: any areaTxt?: any abbreviation?: any superOrgId?: any } const getAffiliationOptions = async ( list?: any[], keys: string[] = ['label', 'value'], val: string[] = ['name', 'id'] ) => { let url = produceModule + 'company_optional_scope_get/' let options: { [key: string]: any }[] = [] try { const res = await cardPrintAxios.get(url, { params: { page: 1, pageSize: 100000 } }) console.log('%c Line:360 🍊🍤 res666', 'color:#7f2b82', res) if ( res.status === 200 && res.data.code === 200 && Array.isArray(res.data?.data) && res.data.data.length > 0 ) { res.data.data.forEach((item: AffiliationRES) => { const obj: { [key: string]: any } = {} keys.forEach((key, index) => { const valueKey = val[index] obj[key] = item[valueKey as keyof AffiliationRES] }) options.push(obj) }) } else { console.error('请求失败:', res.data.msg) options = [] } } catch (error) { console.error('请求失败:', error) options = [] } console.log('%c Line:1338 🥝 result', 'color:#ea7e5c', options) list = options return options } // 获取仓库列表数据 warehouse_get const getWarehouseList = async (par: { list?: any[] keys?: string[] val?: string[] storage_type?: string // 仓库类型 search?: string // 搜索条件, }) => { let { list = [], // 存储接口返回的源数据 keys = ['label', 'value'], val = ['name', 'id'], storage_type = 'CAILIAO', search // 搜索参数 } = par let url = produceModule + 'warehouse_get/' let options: { [key: string]: any }[] = [] try { const res = await cardPrintAxios.get(url, { params: { page: 1, pageSize: 100000, warehouse_type_codes: storage_type, name: search } }) console.log('%c Line:360 🍊 res', 'color:#7f2b82', res) if ( res.status === 200 && res.data.code === 200 && Array.isArray(res.data?.data) && res.data.data.length > 0 ) { list = res.data.data res.data.data.forEach((item: AffiliationRES) => { const obj: { [key: string]: any } = {} keys.forEach((key, index) => { const valueKey = val[index] obj[key] = item[valueKey as keyof AffiliationRES] }) options.push(obj) }) } else { console.error('请求失败:', res.data.msg) list = [] options = [] } } catch (error) { console.error('请求失败:', error) list = [] options = [] } console.log('%c Line:1338 🥝 result', 'color:#ea7e5c', options) return options } // 导出独立实例 export { cardPrintAxios as axios, getAffiliationOptions, getWarehouseList } export default cardPrintAxios