public-form-url.js
755 Bytes
/**
* 构建公开表单完整访问地址(hash 路由)。
* 开发:http://localhost:3000/#/public/forms/{formKey}
* 生产:{origin}/admin/#/public/forms/{formKey}
* @param {string} formKey 表单标识,对应 views/public/forms/registry.js 的 key
* @returns {string}
*/
export function buildPublicFormUrl(formKey) {
if (typeof window === 'undefined' || !window.location) {
return `/#/public/forms/${formKey}`
}
const { origin, pathname } = window.location
let basePath = (pathname || '').replace(/\/index\.html$/i, '').replace(/\/$/, '')
if (!basePath || basePath === '/') {
return `${origin}/#/public/forms/${formKey}`
}
return `${origin}${basePath}/#/public/forms/${formKey}`
}
export default buildPublicFormUrl