Files
zkxw/mobile-h5/utils/oa-h5.js
T
2026-08-12 10:02:31 +08:00

63 lines
1.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { OA_H5_ORIGIN } from './config.js'
import { getToken } from './auth.js'
function trimSlash(s) {
return String(s || '').replace(/\/$/, '')
}
/** 小程序基础库未必有 URLSearchParams,用手写 query 更稳 */
function buildQuery(params) {
const parts = []
Object.keys(params || {}).forEach((k) => {
const v = params[k]
if (v == null || v === '') return
parts.push(encodeURIComponent(k) + '=' + encodeURIComponent(String(v)))
})
return parts.join('&')
}
function withQuery(path, params) {
const base = trimSlash(OA_H5_ORIGIN) + path
const qs = buildQuery(params)
return qs ? base + '?' + qs : base
}
/** 水槽页 URL(须带小程序登录 token,供 OA H5 调 /api) */
export function buildFormSinkUrl() {
const token = getToken()
return withQuery('/oa-form-sink', token ? { token } : {})
}
/** 正式发起页 URL(与水槽同一套拼法,仅多 appId/draftId) */
export function buildOaStartUrl({ appId, draftId } = {}) {
const token = getToken()
const params = {}
if (appId) params.appId = appId
if (draftId) params.draftId = draftId
if (token) params.token = token
return withQuery('/oa-start', params)
}
const TITLE_KEY = 'oa_start_nav_title'
/** 跳转前缓存流程名(勿把中文放进 navigateTo / web-view URL,微信易白屏) */
export function stashOaStartTitle(name) {
const t = String(name || '').trim()
try {
if (t) uni.setStorageSync(TITLE_KEY, t)
else uni.removeStorageSync(TITLE_KEY)
} catch (_) {
/* ignore */
}
}
export function takeOaStartTitle() {
try {
const t = String(uni.getStorageSync(TITLE_KEY) || '').trim()
uni.removeStorageSync(TITLE_KEY)
return t
} catch (_) {
return ''
}
}