199 lines
7.3 KiB
JavaScript
199 lines
7.3 KiB
JavaScript
import { createAppTicket } from '@/api/auth.js'
|
|
|
|
const NATIVE_RULES = [
|
|
{ pattern: /\/apps\/erp\/(dashboard|workbench)/i, route: '/pages/erp/dashboard/index' },
|
|
{ pattern: /\/apps\/erp\/basic\/warehouse/i, route: '/pages/erp/basic/warehouse' },
|
|
{ pattern: /\/apps\/erp\/basic\/product/i, route: '/pages/erp/basic/product' },
|
|
{ pattern: /\/apps\/erp\/suppliers/i, route: '/pages/erp/partner/index?partner_type=supplier' },
|
|
{ pattern: /\/apps\/erp\/customers/i, route: '/pages/erp/partner/index?partner_type=customer' },
|
|
{ pattern: /\/apps\/erp\/purchase\/order/i, route: '/pages/erp/document/index?doc_type=purchase_order' },
|
|
{ pattern: /\/apps\/erp\/purchase\/inbound/i, route: '/pages/erp/document/index?doc_type=purchase_in' },
|
|
{ pattern: /\/apps\/erp\/purchase\/return/i, route: '/pages/erp/document/index?doc_type=purchase_return' },
|
|
{ pattern: /\/apps\/erp\/sales\/order/i, route: '/pages/erp/document/index?doc_type=sales_order' },
|
|
{ pattern: /\/apps\/erp\/sales\/outbound/i, route: '/pages/erp/document/index?doc_type=sales_out' },
|
|
{ pattern: /\/apps\/erp\/sales\/return/i, route: '/pages/erp/document/index?doc_type=sales_return' },
|
|
{ pattern: /\/apps\/erp\/stock\/transfer/i, route: '/pages/erp/document/index?doc_type=transfer' },
|
|
{ pattern: /\/apps\/erp\/stock\/taking/i, route: '/pages/erp/document/index?doc_type=stock_take' },
|
|
{ pattern: /\/apps\/erp\/stock\/inbound/i, route: '/pages/erp/document/index?doc_type=other_in' },
|
|
{ pattern: /\/apps\/erp\/stock\/outbound/i, route: '/pages/erp/document/index?doc_type=other_out' },
|
|
{ pattern: /\/apps\/erp\/stock\/query/i, route: '/pages/erp/stock/index' },
|
|
{ pattern: /\/apps\/erp\/stock\/warning/i, route: '/pages/erp/stock/warning' },
|
|
{ pattern: /\/apps\/erp\/finance\/receivable/i, route: '/pages/erp/finance/bill?bill_type=1' },
|
|
{ pattern: /\/apps\/erp\/finance\/payable/i, route: '/pages/erp/finance/bill?bill_type=2' },
|
|
{ pattern: /\/apps\/erp\/finance\/payment/i, route: '/pages/erp/finance/fund' },
|
|
{ pattern: /\/apps\/erp\/report/i, route: '/pages/erp/report/index' },
|
|
{ pattern: /\/apps\/crm\/project/i, route: '/pages/crm/project/index' },
|
|
{ pattern: /客户项目|项目管理|项目列表|crmProject/i, route: '/pages/crm/project/index' },
|
|
{ pattern: /记事本|笔记|便签|notebook/i, route: '/pages/tools/notepad/index' },
|
|
{ pattern: /账号管理|密码库|passwordStore|password-store/i, route: '/pages/tools/account/index' },
|
|
{ pattern: /提醒|reminder/i, route: '/pages/tools/schedule/reminder' },
|
|
{ pattern: /审批列表|我的审批|我发起的|审批管理|审批申请|approvalList|approval\/list/i, route: '/pages/approval/index' },
|
|
{ pattern: /待我审批|我审批的|审批待办|审批中心|approvalTodo|approval\/todo/i, route: '/pages/approval/verify' },
|
|
{ pattern: /考勤打卡|考勤|打卡|attendance|check-?in/i, route: '/pages/oa/attendance/index' },
|
|
{ pattern: /工作日程|日程|日历|待办|calendar|schedule/i, route: '/pages/tools/schedule/index' },
|
|
{ pattern: /报销|reimburse|expense/i, route: '/pages/tools/expense/index' },
|
|
{ pattern: /工作日报|日报|dailyreport/i, route: '/pages/oa/dailyreport/index' },
|
|
{ pattern: /通知公告|公告|notice/i, route: '/pages/oa/notice/index' },
|
|
{ pattern: /文档库|文档管理|文档图谱|document/i, route: '/pages/oa/document/index' },
|
|
{ pattern: /薪酬|工资|薪资|compensation|payroll/i, route: '/pages/oa/compensation/index' },
|
|
{ pattern: /员工档案|人事档案|档案|employeefile|employeeFile/i, route: '/pages/oa/employeefile/index' },
|
|
{ pattern: /通讯录|联系人|contact/i, route: '/pages/oa/contact/index' }
|
|
]
|
|
|
|
const WEBVIEW_PAGE = '/pages/apps/webview'
|
|
|
|
// 常用功能默认展示顺序(用户未自定义前按此顺序排列)
|
|
export const DEFAULT_QUICK_TITLES = [
|
|
'考勤打卡',
|
|
'报销管理',
|
|
'工作日程',
|
|
'通讯录',
|
|
'审批列表',
|
|
'文档库',
|
|
'工作日报'
|
|
]
|
|
|
|
// 常用功能标题对应的图标(菜单未配图标时兜底)
|
|
export const QUICK_TITLE_ICONS = {
|
|
'考勤打卡': 'alarm-clock',
|
|
'报销管理': 'receipt',
|
|
'工作日程': 'calendar-days',
|
|
'通讯录': 'address-book',
|
|
'审批列表': 'clipboard-check',
|
|
'文档库': 'folder-open',
|
|
'工作日报': 'book'
|
|
}
|
|
|
|
/**
|
|
* 按默认常用功能顺序排序,未命中的保持原有相对顺序
|
|
* @param {Array} list 菜单/应用列表
|
|
* @param {Array<string>} titles 优先顺序
|
|
*/
|
|
export function orderQuickMenus(list = [], titles = DEFAULT_QUICK_TITLES) {
|
|
const items = Array.isArray(list) ? list : []
|
|
const rank = new Map(titles.map((t, i) => [String(t).trim(), i]))
|
|
return items
|
|
.map((item, index) => ({ item, index }))
|
|
.sort((a, b) => {
|
|
const ta = a.item && (a.item.title || a.item.name)
|
|
const tb = b.item && (b.item.title || b.item.name)
|
|
const ra = rank.has(ta) ? rank.get(ta) : titles.length
|
|
const rb = rank.has(tb) ? rank.get(tb) : titles.length
|
|
if (ra !== rb) return ra - rb
|
|
return a.index - b.index
|
|
})
|
|
.map((entry) => entry.item)
|
|
}
|
|
|
|
export const WEB_RULES = [
|
|
'审批设置',
|
|
'审批流配置',
|
|
'审批流程',
|
|
'审批配置'
|
|
]
|
|
|
|
const DEVELOPING_PAGE = '/pages/common/developing'
|
|
|
|
function openDeveloping(name) {
|
|
uni.navigateTo({
|
|
url: DEVELOPING_PAGE + '?t=' + encodeURIComponent(name || '功能')
|
|
})
|
|
}
|
|
|
|
export function resolveNativeRoute(menu = {}) {
|
|
const title = String(menu.title || '')
|
|
const path = String(menu.path || '')
|
|
const haystack = title + ' ' + path
|
|
const hit = NATIVE_RULES.find((r) => r.pattern.test(haystack))
|
|
console.log('[nav] resolveNativeRoute', { title, path, hit: hit ? hit.route : '' })
|
|
return hit ? hit.route : ''
|
|
}
|
|
|
|
export function isMenuLocked(menu = {}) {
|
|
return menu.locked === true || menu.locked === 1
|
|
}
|
|
|
|
export function openMenu(menu, fallbackTitle = '') {
|
|
const name = (menu && (menu.title || menu.name)) || fallbackTitle || '该功能'
|
|
|
|
if (!menu) {
|
|
uni.showToast({ title: name + '暂未开放', icon: 'none' })
|
|
return
|
|
}
|
|
|
|
if (isMenuLocked(menu)) {
|
|
uni.showModal({
|
|
title: '功能未开通',
|
|
content: '「' + name + '」不在当前套餐范围内,请联系管理员开通后再使用。',
|
|
showCancel: false,
|
|
confirmText: '知道了'
|
|
})
|
|
return
|
|
}
|
|
|
|
if (menu.leaf === false) {
|
|
uni.showToast({ title: '请选择「' + name + '」下的具体功能', icon: 'none' })
|
|
return
|
|
}
|
|
|
|
const native = resolveNativeRoute(menu)
|
|
if (native) {
|
|
uni.navigateTo({ url: native })
|
|
return
|
|
}
|
|
|
|
const target = String(menu.path || '').trim()
|
|
if (/^https?:\/\//i.test(target)) {
|
|
openRawUrl(target, name)
|
|
return
|
|
}
|
|
|
|
const haystack = name + ' ' + target
|
|
if (target && WEB_RULES.some((kw) => haystack.indexOf(kw) !== -1)) {
|
|
openWebPage(target, name)
|
|
return
|
|
}
|
|
|
|
openDeveloping(name)
|
|
}
|
|
|
|
export async function openWebPage(path, title = '') {
|
|
const name = title || '功能'
|
|
const target = String(path || '').trim()
|
|
if (!target) {
|
|
uni.showToast({ title: name + '暂未开放', icon: 'none' })
|
|
return
|
|
}
|
|
|
|
let ticket = ''
|
|
try {
|
|
const data = await createAppTicket()
|
|
ticket = (data && data.ticket) || ''
|
|
} catch (e) {
|
|
console.warn('[nav] 获取免登录票据失败,降级为直接打开:', e)
|
|
}
|
|
|
|
uni.navigateTo({
|
|
url:
|
|
WEBVIEW_PAGE +
|
|
'?p=' +
|
|
encodeURIComponent(target) +
|
|
'&k=' +
|
|
encodeURIComponent(ticket) +
|
|
'&t=' +
|
|
encodeURIComponent(name)
|
|
})
|
|
}
|
|
|
|
export function openRawUrl(url, title = '') {
|
|
if (!url) return
|
|
uni.navigateTo({
|
|
url:
|
|
WEBVIEW_PAGE +
|
|
'?p=' +
|
|
encodeURIComponent(url) +
|
|
'&t=' +
|
|
encodeURIComponent(title || '功能')
|
|
})
|
|
}
|