feat(微信小程序): 授权页支持主域名校验、代注册入口与左菜单+右明细结构
- 主域名校验:复用 frontBrand 导出 isMainDomainHost/normalizeFrontHost/getMainDomainHosts,非主域名禁用授权/代注册并提示 - 新增「代注册小程序」按钮:wechat.getRegisterUrl 取链接,在新小窗打开 - 已授权改为左菜单+右明细(基础信息/认证状态/备案配置/支付配置/发布/微信用户),左右各自滚动、边框到底 - 基础信息改为「名称:不可编辑输入框」;头像只显示图片;隐藏启用状态/所属仓库/记录ID - 修正 auth_time(Unix 秒)与 ISO 时间本地化;func_info JSON 解析为功能标签
This commit is contained in:
parent
401d1aa3df
commit
fc5a80717e
@ -20,7 +20,7 @@ export type WeChatAuthUrlPayload = {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取微信授权链接(由用户点击「去授权」时调用,避免页面加载即跳转/弹窗被拦截)。
|
* 获取微信授权链接(由用户点击「去授权」时调用,避免页面加载即跳转/弹窗被拦截)。
|
||||||
* 返回值中链接字段名做多形态兼容,取值见页面 pickAuthUrl()。
|
* 返回值中链接字段名做多形态兼容,取值见页面 pickUrl()。
|
||||||
*/
|
*/
|
||||||
export function wechatGetAuthUrl(
|
export function wechatGetAuthUrl(
|
||||||
data: Record<string, unknown> = {}
|
data: Record<string, unknown> = {}
|
||||||
@ -38,8 +38,30 @@ export function wechatGetAuthUrl(
|
|||||||
} as any)
|
} as any)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取「代注册小程序」链接(第三方平台快速创建小程序):
|
||||||
|
* 同样由用户点击按钮后才请求,并在新小窗口中打开;注册完成后调用业务侧查询接口刷新。
|
||||||
|
* 若后端方法名不同,仅需改此处 method。
|
||||||
|
*/
|
||||||
|
export function wechatGetRegisterUrl(
|
||||||
|
data: Record<string, unknown> = {}
|
||||||
|
): Promise<{ code?: number; message?: string; data?: WeChatAuthUrlPayload } & Record<string, unknown>> {
|
||||||
|
return request({
|
||||||
|
url: '/system',
|
||||||
|
method: 'post',
|
||||||
|
params: {
|
||||||
|
method: 'wechat.getRegisterUrl',
|
||||||
|
v,
|
||||||
|
timestamp: new Date().getTime()
|
||||||
|
},
|
||||||
|
data,
|
||||||
|
isSystemApi: true
|
||||||
|
} as any)
|
||||||
|
}
|
||||||
|
|
||||||
export const wechat = {
|
export const wechat = {
|
||||||
getAuthUrl: wechatGetAuthUrl
|
getAuthUrl: wechatGetAuthUrl,
|
||||||
|
getRegisterUrl: wechatGetRegisterUrl
|
||||||
}
|
}
|
||||||
|
|
||||||
export default wechat
|
export default wechat
|
||||||
|
|||||||
@ -32,7 +32,7 @@ function resolveFrontBrandExemptHosts(): Set<string> {
|
|||||||
const FRONT_BRAND_EXEMPT_HOSTS = resolveFrontBrandExemptHosts()
|
const FRONT_BRAND_EXEMPT_HOSTS = resolveFrontBrandExemptHosts()
|
||||||
|
|
||||||
/** 归一化访问域名:去协议/路径/端口、转小写,用于豁免判定与请求域名 */
|
/** 归一化访问域名:去协议/路径/端口、转小写,用于豁免判定与请求域名 */
|
||||||
function normalizeFrontHost(raw?: string): string {
|
export function normalizeFrontHost(raw?: string): string {
|
||||||
let host = (raw || '').trim().replace(/^https?:\/\//, '')
|
let host = (raw || '').trim().replace(/^https?:\/\//, '')
|
||||||
const slashIdx = host.indexOf('/')
|
const slashIdx = host.indexOf('/')
|
||||||
if (slashIdx >= 0) host = host.slice(0, slashIdx)
|
if (slashIdx >= 0) host = host.slice(0, slashIdx)
|
||||||
@ -41,6 +41,21 @@ function normalizeFrontHost(raw?: string): string {
|
|||||||
return host.toLowerCase()
|
return host.toLowerCase()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 主域名(豁免域名)清单:与品牌豁免同源,供其它「仅主域名可用」能力复用 */
|
||||||
|
export function getMainDomainHosts(): string[] {
|
||||||
|
return Array.from(FRONT_BRAND_EXEMPT_HOSTS)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前访问域名是否为主域名(= 品牌豁免域名,来源 VITE_FRONT_CONFIG_EXEMPT_HOSTS)。
|
||||||
|
* 用途:微信小程序授权页只能从主域名进入(自持域名下微信授权回调无法回到本系统),
|
||||||
|
* 非主域名时前端禁用「去授权」入口并提示。
|
||||||
|
*/
|
||||||
|
export function isMainDomainHost(raw?: string): boolean {
|
||||||
|
const host = normalizeFrontHost(raw ?? window.location.hostname)
|
||||||
|
return Boolean(host) && FRONT_BRAND_EXEMPT_HOSTS.has(host)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 前端独立部署品牌(frontConfig.getByDomain 消费端)
|
* 前端独立部署品牌(frontConfig.getByDomain 消费端)
|
||||||
*
|
*
|
||||||
|
|||||||
@ -3,11 +3,14 @@
|
|||||||
对接接口:
|
对接接口:
|
||||||
- setting.warehouse.getweChatApp(settingWarehouseGetWeChatApp):拉取当前仓库已授权的微信小程序配置
|
- setting.warehouse.getweChatApp(settingWarehouseGetWeChatApp):拉取当前仓库已授权的微信小程序配置
|
||||||
- wechat.getAuthUrl(wechatGetAuthUrl):未配置时点击「去授权」获取授权链接,并在新小窗口中打开
|
- wechat.getAuthUrl(wechatGetAuthUrl):未配置时点击「去授权」获取授权链接,并在新小窗口中打开
|
||||||
|
- wechat.getRegisterUrl(wechatGetRegisterUrl):点击「代注册小程序」获取代注册链接,并在新小窗口中打开
|
||||||
|
|
||||||
交互约定:
|
交互约定:
|
||||||
1) 页面挂载即拉取配置;无配置(未授权)时提示「需要授权」并高亮「去授权」入口
|
1) 页面挂载即拉取配置;无配置(未授权)时提示「需要授权」并高亮「去授权」入口
|
||||||
2) 授权链接**不自动打开**:必须用户点击「去授权」按钮后才请求 wechat.getAuthUrl 并弹小窗
|
2) 授权/代注册链接**不自动打开**:必须用户点击按钮后才请求接口并弹小窗
|
||||||
3) 小窗口打开后:轮询配置,授权完成自动刷新;小窗关闭后做最后一次刷新
|
3) 小窗口打开后:轮询配置,流程完成自动刷新;小窗关闭后做最后一次刷新
|
||||||
|
4) 域名限制:微信小程序授权/代注册页只能从**主域名**进入(主域名 = 品牌豁免域名
|
||||||
|
VITE_FRONT_CONFIG_EXEMPT_HOSTS,与 frontBrand 同源);非主域名下禁用按钮并提示
|
||||||
|
|
||||||
使用方:
|
使用方:
|
||||||
1) basicManagement/newview 的 viewType='form' 标签页「微信小程序」
|
1) basicManagement/newview 的 viewType='form' 标签页「微信小程序」
|
||||||
@ -21,64 +24,132 @@
|
|||||||
<span class="sub">
|
<span class="sub">
|
||||||
当前仓库已授权的微信小程序配置(数据来自微信授权,只读)
|
当前仓库已授权的微信小程序配置(数据来自微信授权,只读)
|
||||||
<template v-if="lastLoadedAt">|更新于 {{ lastLoadedAt }}</template>
|
<template v-if="lastLoadedAt">|更新于 {{ lastLoadedAt }}</template>
|
||||||
|
|当前域名:{{ currentHost }}{{ isMainDomain ? '' : '(非主域名,不可授权)' }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="header-actions">
|
<div class="header-actions">
|
||||||
<el-button :disabled="pageLoading" @click="loadConfig">刷新</el-button>
|
<el-button :disabled="pageLoading" @click="loadConfig">刷新</el-button>
|
||||||
<el-button type="primary" :loading="authUrlLoading" @click="handleAuthorize">
|
<el-tooltip :disabled="isMainDomain" :content="mainDomainTip" placement="bottom-end">
|
||||||
|
<span class="mp-auth-trigger">
|
||||||
|
<el-button
|
||||||
|
:disabled="!isMainDomain"
|
||||||
|
:loading="registerUrlLoading"
|
||||||
|
@click="handleRegister"
|
||||||
|
>代注册小程序</el-button>
|
||||||
|
</span>
|
||||||
|
</el-tooltip>
|
||||||
|
<el-tooltip :disabled="isMainDomain" :content="mainDomainTip" placement="bottom-end">
|
||||||
|
<span class="mp-auth-trigger">
|
||||||
|
<el-button
|
||||||
|
type="primary"
|
||||||
|
:disabled="!isMainDomain"
|
||||||
|
:loading="authUrlLoading"
|
||||||
|
@click="handleAuthorize"
|
||||||
|
>
|
||||||
{{ authorized ? '重新授权' : '去授权' }}
|
{{ authorized ? '重新授权' : '去授权' }}
|
||||||
</el-button>
|
</el-button>
|
||||||
|
</span>
|
||||||
|
</el-tooltip>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- ===== 未授权:提示需要授权 ===== -->
|
<!-- ===== 未授权:提示需要授权 ===== -->
|
||||||
<template v-if="!pageLoading && !authorized">
|
<template v-if="!pageLoading && !authorized">
|
||||||
<el-alert
|
<el-alert
|
||||||
type="warning"
|
:type="isMainDomain ? 'warning' : 'error'"
|
||||||
show-icon
|
show-icon
|
||||||
:closable="false"
|
:closable="false"
|
||||||
class="mp-config-alert"
|
class="mp-config-alert"
|
||||||
title="当前仓库尚未授权微信小程序,需要先完成授权"
|
:title="
|
||||||
description="点击右上角「去授权」后,会在新小窗口中打开微信授权页;完成授权后本页会自动刷新。"
|
isMainDomain
|
||||||
|
? '当前仓库尚未授权微信小程序,需要先完成授权'
|
||||||
|
: '当前访问域名不支持微信授权,请从主域名进入'
|
||||||
|
"
|
||||||
|
:description="
|
||||||
|
isMainDomain
|
||||||
|
? '点击右上角「去授权」后,会在新小窗口中打开微信授权页;完成授权后本页会自动刷新。'
|
||||||
|
: `微信小程序授权页只能从主域名进入(当前域名:${currentHost})。请改用主域名访问本页后再授权;配置查看不受影响。`
|
||||||
|
"
|
||||||
/>
|
/>
|
||||||
<div class="mp-empty">
|
<div class="mp-empty">
|
||||||
<el-empty description="暂无微信小程序配置">
|
<el-empty :description="isMainDomain ? '暂无微信小程序配置' : '当前域名不可授权,暂无配置'">
|
||||||
<el-button type="primary" :loading="authUrlLoading" @click="handleAuthorize">
|
<el-tooltip :disabled="isMainDomain" :content="mainDomainTip" placement="top">
|
||||||
去授权
|
<span class="mp-auth-trigger">
|
||||||
</el-button>
|
<el-button
|
||||||
|
type="primary"
|
||||||
|
:disabled="!isMainDomain"
|
||||||
|
:loading="authUrlLoading"
|
||||||
|
@click="handleAuthorize"
|
||||||
|
>去授权</el-button>
|
||||||
|
</span>
|
||||||
|
</el-tooltip>
|
||||||
</el-empty>
|
</el-empty>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<!-- ===== 已授权:只读回显 ===== -->
|
<!-- ===== 已授权:左菜单 + 右明细 ===== -->
|
||||||
<template v-else-if="authorized">
|
<div v-else-if="authorized" class="mp-layout">
|
||||||
|
<!-- 左侧菜单 -->
|
||||||
|
<aside class="mp-nav">
|
||||||
|
<ul class="mp-nav__list">
|
||||||
|
<li
|
||||||
|
v-for="menu in MENU_LIST"
|
||||||
|
:key="menu.key"
|
||||||
|
class="mp-nav__item"
|
||||||
|
:class="{ 'is-active': activeMenu === menu.key }"
|
||||||
|
@click="activeMenu = menu.key"
|
||||||
|
>
|
||||||
|
<el-icon class="mp-nav__icon"><component :is="menu.icon" /></el-icon>
|
||||||
|
<span class="mp-nav__label">{{ menu.label }}</span>
|
||||||
|
<el-tag
|
||||||
|
v-if="menu.pending"
|
||||||
|
class="mp-nav__tag"
|
||||||
|
size="small"
|
||||||
|
type="info"
|
||||||
|
effect="plain"
|
||||||
|
>待接入</el-tag>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</aside>
|
||||||
|
|
||||||
|
<!-- 右侧明细 -->
|
||||||
|
<section class="mp-detail">
|
||||||
|
<!-- ① 基础信息(接口已有:setting.warehouse.getweChatApp) -->
|
||||||
|
<template v-if="activeMenu === 'basic'">
|
||||||
<section class="mp-panel">
|
<section class="mp-panel">
|
||||||
<header class="mp-panel__head">
|
<header class="mp-panel__head">
|
||||||
<h3 class="mp-panel__title">小程序信息</h3>
|
<h3 class="mp-panel__title">小程序基础信息</h3>
|
||||||
<p class="mp-panel__desc">来源:setting.warehouse.getweChatApp(如需变更请重新授权)</p>
|
<p class="mp-panel__desc">来源:setting.warehouse.getweChatApp(如需变更请重新授权)</p>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<el-descriptions :column="2" border size="small" class="mp-descriptions">
|
<el-form
|
||||||
<el-descriptions-item
|
label-width="150px"
|
||||||
|
label-position="right"
|
||||||
|
class="mp-info-form"
|
||||||
|
>
|
||||||
|
<el-form-item
|
||||||
v-for="item in infoItems"
|
v-for="item in infoItems"
|
||||||
:key="`mp-info-${item.key}`"
|
:key="`mp-info-${item.key}`"
|
||||||
:label="item.label"
|
:label="item.label"
|
||||||
:span="item.wide ? 2 : 1"
|
|
||||||
>
|
>
|
||||||
<div class="mp-value">
|
<div class="mp-field-row">
|
||||||
|
<el-input
|
||||||
|
v-if="!item.isImage"
|
||||||
|
:model-value="item.value"
|
||||||
|
disabled
|
||||||
|
class="mp-field"
|
||||||
|
:title="item.value"
|
||||||
|
/>
|
||||||
<el-image
|
<el-image
|
||||||
v-if="item.isImage"
|
v-if="item.isImage"
|
||||||
:src="item.value"
|
:src="item.imageSrc"
|
||||||
fit="contain"
|
:preview-src-list="[item.imageSrc]"
|
||||||
class="mp-value__image"
|
preview-teleported
|
||||||
|
fit="cover"
|
||||||
|
class="mp-thumb"
|
||||||
>
|
>
|
||||||
<template #error><span class="mp-value__tip">{{ item.value }}</span></template>
|
<template #error><span class="mp-thumb__tip">图片无法加载</span></template>
|
||||||
</el-image>
|
</el-image>
|
||||||
<el-tag v-else-if="item.isStatus" :type="item.statusType" size="small" effect="light">
|
|
||||||
{{ item.value }}
|
|
||||||
</el-tag>
|
|
||||||
<span v-else class="mp-value__text" :title="item.value">{{ item.value }}</span>
|
|
||||||
|
|
||||||
<el-button
|
<el-button
|
||||||
v-if="item.isSecret"
|
v-if="item.isSecret"
|
||||||
link
|
link
|
||||||
@ -87,8 +158,20 @@
|
|||||||
@click="copyText(config[item.key])"
|
@click="copyText(config[item.key])"
|
||||||
>复制</el-button>
|
>复制</el-button>
|
||||||
</div>
|
</div>
|
||||||
</el-descriptions-item>
|
|
||||||
</el-descriptions>
|
<!-- 授权功能集(func_info 为 JSON 字符串):解析后逐项展示 -->
|
||||||
|
<div v-if="item.isFuncInfo && funcInfoItems.length" class="mp-func-list">
|
||||||
|
<el-tag
|
||||||
|
v-for="fn in funcInfoItems"
|
||||||
|
:key="`mp-func-${fn.id}`"
|
||||||
|
class="mp-func-tag"
|
||||||
|
size="small"
|
||||||
|
effect="plain"
|
||||||
|
:title="fn.raw"
|
||||||
|
>{{ fn.label }}</el-tag>
|
||||||
|
</div>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<!-- 未纳管字段(后端新增字段自动展示,便于核对) -->
|
<!-- 未纳管字段(后端新增字段自动展示,便于核对) -->
|
||||||
@ -98,23 +181,34 @@
|
|||||||
<p class="mp-panel__desc">接口返回的其余字段</p>
|
<p class="mp-panel__desc">接口返回的其余字段</p>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<el-descriptions :column="2" border size="small" class="mp-descriptions">
|
<el-form
|
||||||
<el-descriptions-item
|
label-width="150px"
|
||||||
|
label-position="right"
|
||||||
|
class="mp-info-form"
|
||||||
|
>
|
||||||
|
<el-form-item
|
||||||
v-for="item in otherItems"
|
v-for="item in otherItems"
|
||||||
:key="`mp-other-${item.key}`"
|
:key="`mp-other-${item.key}`"
|
||||||
:label="item.label"
|
:label="item.label"
|
||||||
:span="item.wide ? 2 : 1"
|
|
||||||
>
|
>
|
||||||
<div class="mp-value">
|
<div class="mp-field-row">
|
||||||
|
<el-input
|
||||||
|
v-if="!item.isImage"
|
||||||
|
:model-value="item.value"
|
||||||
|
disabled
|
||||||
|
class="mp-field"
|
||||||
|
:title="item.value"
|
||||||
|
/>
|
||||||
<el-image
|
<el-image
|
||||||
v-if="item.isImage"
|
v-if="item.isImage"
|
||||||
:src="item.value"
|
:src="item.imageSrc"
|
||||||
fit="contain"
|
:preview-src-list="[item.imageSrc]"
|
||||||
class="mp-value__image"
|
preview-teleported
|
||||||
|
fit="cover"
|
||||||
|
class="mp-thumb"
|
||||||
>
|
>
|
||||||
<template #error><span class="mp-value__tip">{{ item.value }}</span></template>
|
<template #error><span class="mp-thumb__tip">图片无法加载</span></template>
|
||||||
</el-image>
|
</el-image>
|
||||||
<span v-else class="mp-value__text" :title="item.value">{{ item.value }}</span>
|
|
||||||
<el-button
|
<el-button
|
||||||
v-if="item.isSecret"
|
v-if="item.isSecret"
|
||||||
link
|
link
|
||||||
@ -123,21 +217,55 @@
|
|||||||
@click="copyText(config[item.key])"
|
@click="copyText(config[item.key])"
|
||||||
>复制</el-button>
|
>复制</el-button>
|
||||||
</div>
|
</div>
|
||||||
</el-descriptions-item>
|
</el-form-item>
|
||||||
</el-descriptions>
|
</el-form>
|
||||||
</section>
|
</section>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<!-- ② 其余菜单:页面结构已预留,接口待定 -->
|
||||||
|
<template v-else>
|
||||||
|
<section class="mp-panel">
|
||||||
|
<header class="mp-panel__head">
|
||||||
|
<h3 class="mp-panel__title">{{ currentMenu?.label }}</h3>
|
||||||
|
<p class="mp-panel__desc">{{ currentMenu?.desc }}</p>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<el-alert
|
||||||
|
type="info"
|
||||||
|
show-icon
|
||||||
|
:closable="false"
|
||||||
|
class="mp-config-alert"
|
||||||
|
title="接口待定:本菜单页面结构已预留"
|
||||||
|
description="后端接口确定后在此接入;下方为规划中的内容分区,仅占位。"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div class="mp-placeholder">
|
||||||
|
<div
|
||||||
|
v-for="block in currentMenu?.blocks ?? []"
|
||||||
|
:key="block.title"
|
||||||
|
class="mp-placeholder__block"
|
||||||
|
>
|
||||||
|
<h4 class="mp-placeholder__title">{{ block.title }}</h4>
|
||||||
|
<p class="mp-placeholder__desc">{{ block.desc }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</template>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
|
import { computed, onBeforeUnmount, onMounted, ref, type Component } from 'vue'
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
|
import { Document, InfoFilled, Medal, Promotion, User, Wallet } from '@element-plus/icons-vue'
|
||||||
import {
|
import {
|
||||||
settingWarehouseGetWeChatApp,
|
settingWarehouseGetWeChatApp,
|
||||||
unwrapSettingWarehousePayload
|
unwrapSettingWarehousePayload
|
||||||
} from '@/api/setting.warehouse/settingwarehouse'
|
} from '@/api/setting.warehouse/settingwarehouse'
|
||||||
import { wechatGetAuthUrl } from '@/api/wechat/wechat'
|
import { wechatGetAuthUrl, wechatGetRegisterUrl } from '@/api/wechat/wechat'
|
||||||
|
import { isMainDomainHost, normalizeFrontHost } from '@/stores/modules/frontBrand'
|
||||||
defineOptions({ name: 'MiniProgramConfigForm' })
|
defineOptions({ name: 'MiniProgramConfigForm' })
|
||||||
|
|
||||||
const okCode = (code: unknown) => code === 1 || code === 200 || code === 0
|
const okCode = (code: unknown) => code === 1 || code === 200 || code === 0
|
||||||
@ -161,11 +289,10 @@ const NEUTRAL_KEYS = new Set([
|
|||||||
type FieldDefinition = {
|
type FieldDefinition = {
|
||||||
label: string
|
label: string
|
||||||
keys: string[]
|
keys: string[]
|
||||||
wide?: boolean
|
|
||||||
/** 值翻译(如 1=启用 / 0=停用) */
|
/** 值翻译(如 1=启用 / 0=停用) */
|
||||||
valueMap?: Record<string, string>
|
valueMap?: Record<string, string>
|
||||||
/** 用 el-tag 渲染 */
|
/** 不展示:仅用于消耗字段(不让其落到「其他信息」兜底区),如 id / warehouse_id */
|
||||||
tag?: boolean
|
hidden?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const FIELD_DEFINITIONS: FieldDefinition[] = [
|
const FIELD_DEFINITIONS: FieldDefinition[] = [
|
||||||
@ -175,22 +302,19 @@ const FIELD_DEFINITIONS: FieldDefinition[] = [
|
|||||||
{ label: '原始ID', keys: ['user_name', 'original_id', 'gh_id', 'username'] },
|
{ label: '原始ID', keys: ['user_name', 'original_id', 'gh_id', 'username'] },
|
||||||
{ label: '主体名称', keys: ['principal_name', 'principal'] },
|
{ label: '主体名称', keys: ['principal_name', 'principal'] },
|
||||||
{ label: '微信号/别名', keys: ['alias', 'wechat_id'] },
|
{ label: '微信号/别名', keys: ['alias', 'wechat_id'] },
|
||||||
{
|
{ label: '授权状态', keys: ['auth_status', 'status', 'is_authorized', 'authorized'] },
|
||||||
label: '启用状态',
|
|
||||||
keys: ['is_enabled', 'enabled'],
|
|
||||||
valueMap: { '1': '启用', '0': '停用' },
|
|
||||||
tag: true
|
|
||||||
},
|
|
||||||
{ label: '授权状态', keys: ['auth_status', 'status', 'is_authorized', 'authorized'], tag: true },
|
|
||||||
{ label: '所属仓库', keys: ['warehouse_id'] },
|
|
||||||
{ label: '授权码', keys: ['authorization_code', 'auth_code'] },
|
|
||||||
{ label: '授权时间', keys: ['auth_time', 'authorized_at', 'authorize_time', 'auth_at'] },
|
{ label: '授权时间', keys: ['auth_time', 'authorized_at', 'authorize_time', 'auth_at'] },
|
||||||
{ label: '到期时间', keys: ['expires_at', 'expire_time', 'authorization_expires_at', 'expired_at'] },
|
{ label: '到期时间', keys: ['expires_at', 'expire_time', 'authorization_expires_at', 'expired_at'] },
|
||||||
{ label: '授权功能集', keys: ['func_info'], wide: true },
|
{ label: '授权功能集', keys: ['func_info'] },
|
||||||
{ label: '头像/二维码', keys: ['head_img', 'headimgurl', 'head_img_url', 'qrcode_url', 'avatar'] },
|
{ label: '头像', keys: ['head_img', 'headimgurl', 'head_img_url', 'avatar'] },
|
||||||
{ label: '记录ID', keys: ['id'] },
|
{ label: '二维码', keys: ['qrcode_url'] },
|
||||||
|
{ label: '授权码', keys: ['authorization_code', 'auth_code'] },
|
||||||
|
{ label: '创建时间', keys: ['created_at'] },
|
||||||
{ label: '更新时间', keys: ['updated_at'] },
|
{ label: '更新时间', keys: ['updated_at'] },
|
||||||
{ label: '创建时间', keys: ['created_at'] }
|
// 以下字段按需求不展示(hidden 仅用于占位消耗,避免落入「其他信息」)
|
||||||
|
{ label: '启用状态', keys: ['is_enabled', 'enabled'], hidden: true },
|
||||||
|
{ label: '所属仓库', keys: ['warehouse_id'], hidden: true },
|
||||||
|
{ label: '记录ID', keys: ['id'], hidden: true }
|
||||||
]
|
]
|
||||||
|
|
||||||
/** 授权链接可能的字段名(按优先级取值) */
|
/** 授权链接可能的字段名(按优先级取值) */
|
||||||
@ -214,31 +338,144 @@ const SECRET_KEY_PATTERN = /secret|token|key|password/i
|
|||||||
/** 视为图片地址的字段 */
|
/** 视为图片地址的字段 */
|
||||||
const IMAGE_KEY_PATTERN = /img|image|avatar|logo|qrcode|qr_code/i
|
const IMAGE_KEY_PATTERN = /img|image|avatar|logo|qrcode|qr_code/i
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// 左侧菜单(已授权时:左菜单 + 右明细)
|
||||||
|
// ============================================================
|
||||||
|
/** 菜单下规划中的内容分区(接口未接入时占位展示) */
|
||||||
|
type MenuBlock = { title: string; desc: string }
|
||||||
|
|
||||||
|
type MiniProgramMenuItem = {
|
||||||
|
key: string
|
||||||
|
label: string
|
||||||
|
icon: Component
|
||||||
|
desc: string
|
||||||
|
/** 接口待定:仅预留页面结构 */
|
||||||
|
pending?: boolean
|
||||||
|
/** 规划中的内容分区(占位) */
|
||||||
|
blocks?: MenuBlock[]
|
||||||
|
}
|
||||||
|
|
||||||
|
const MENU_LIST: MiniProgramMenuItem[] = [
|
||||||
|
{
|
||||||
|
key: 'basic',
|
||||||
|
label: '基础信息',
|
||||||
|
icon: InfoFilled,
|
||||||
|
desc: '小程序授权基础信息(接口已接入:setting.warehouse.getweChatApp)'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'cert',
|
||||||
|
label: '认证状态',
|
||||||
|
icon: Medal,
|
||||||
|
desc: '小程序微信认证状态、认证主体与有效期(接口待定)',
|
||||||
|
pending: true,
|
||||||
|
blocks: [
|
||||||
|
{ title: '认证信息', desc: '认证类型 / 认证主体名称 / 认证主体证件号 / 认证有效期' },
|
||||||
|
{ title: '认证材料与支付', desc: '认证订单与支付记录 / 认证结果通知 / 年审提醒' },
|
||||||
|
{ title: '状态与记录', desc: '当前认证状态 / 认证历史记录 / 失败原因与重试' }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'beian',
|
||||||
|
label: '备案配置',
|
||||||
|
icon: Document,
|
||||||
|
desc: '小程序 ICP 备案主体、备案信息与核验材料(接口待定)',
|
||||||
|
pending: true,
|
||||||
|
blocks: [
|
||||||
|
{ title: '备案主体', desc: '主体名称 / 主体证件类型 / 主体证件号 / 负责人信息' },
|
||||||
|
{ title: '小程序备案信息', desc: '备案号 / 服务内容类型 / 备案状态 / 审核意见' },
|
||||||
|
{ title: '材料与核验', desc: '证件照片 / 人脸核验记录 / 承诺书上传(预预留上传入口)' }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'pay',
|
||||||
|
label: '支付配置',
|
||||||
|
icon: Wallet,
|
||||||
|
desc: '微信支付商户信息、密钥证书与回调地址(接口待定)',
|
||||||
|
pending: true,
|
||||||
|
blocks: [
|
||||||
|
{ title: '商户信息', desc: '商户号 / 商户主体 / 结算账户 / 与小程序绑定关系' },
|
||||||
|
{ title: '密钥与证书', desc: 'API 密钥 / APIv3 密钥 / 证书序列号 / 证书文件上传' },
|
||||||
|
{ title: '回调与通知', desc: '支付回调地址 / 退款回调地址 / 通知模板' }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'publish',
|
||||||
|
label: '发布',
|
||||||
|
icon: Promotion,
|
||||||
|
desc: '代码包上传、版本审核与发布记录(接口待定)',
|
||||||
|
pending: true,
|
||||||
|
blocks: [
|
||||||
|
{ title: '版本与审核', desc: '当前线上版本 / 审核中版本 / 提交审核入口' },
|
||||||
|
{ title: '代码包管理', desc: '体验版 / 上传代码包 / 版本描述' },
|
||||||
|
{ title: '发布记录', desc: '版本号 / 发布时间 / 发布人 / 回滚操作' }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'wxuser',
|
||||||
|
label: '微信用户',
|
||||||
|
icon: User,
|
||||||
|
desc: '小程序侧用户(openid)与系统账号绑定关系(接口待定)',
|
||||||
|
pending: true,
|
||||||
|
blocks: [
|
||||||
|
{ title: '用户列表', desc: 'openid / unionid / 昵称 / 头像 / 关注时间(预留分页与筛选)' },
|
||||||
|
{ title: '绑定关系', desc: '用户与系统账号的绑定 / 解绑操作' },
|
||||||
|
{ title: '用户状态', desc: '拉黑 / 备注 / 操作日志' }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
/** 当前选中的左侧菜单(默认基础信息) */
|
||||||
|
const activeMenu = ref(MENU_LIST[0]?.key ?? 'basic')
|
||||||
|
/** 当前菜单项(兼容未知 key) */
|
||||||
|
const currentMenu = computed<MiniProgramMenuItem | undefined>(() =>
|
||||||
|
MENU_LIST.find((menu) => menu.key === activeMenu.value) ?? MENU_LIST[0]
|
||||||
|
)
|
||||||
|
|
||||||
|
/** 基础信息/其他信息的一行展示项(值为不可编辑输入框;图片类只展示图片) */
|
||||||
type DisplayItem = {
|
type DisplayItem = {
|
||||||
key: string
|
key: string
|
||||||
label: string
|
label: string
|
||||||
|
/** 展示值(已翻译、已格式化;密钥类已打码) */
|
||||||
value: string
|
value: string
|
||||||
wide?: boolean
|
/** 图片地址(仅图片类字段有值,已做 https 归一化) */
|
||||||
|
imageSrc: string
|
||||||
isImage: boolean
|
isImage: boolean
|
||||||
isSecret: boolean
|
isSecret: boolean
|
||||||
isStatus: boolean
|
/** 授权功能集:下方额外渲染解析后的功能项 */
|
||||||
statusType: 'success' | 'info' | 'warning' | 'danger'
|
isFuncInfo: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 授权功能集单项(func_info 为 JSON 字符串:[{funcscope_category:{id}}…]) */
|
||||||
|
type FuncInfoItem = { id: string; label: string; raw: string }
|
||||||
|
|
||||||
// ============================================================
|
// ============================================================
|
||||||
// 状态
|
// 状态
|
||||||
// ============================================================
|
// ============================================================
|
||||||
const pageLoading = ref(false)
|
const pageLoading = ref(false)
|
||||||
const authUrlLoading = ref(false)
|
const authUrlLoading = ref(false)
|
||||||
|
const registerUrlLoading = ref(false)
|
||||||
const config = ref<Record<string, unknown>>({})
|
const config = ref<Record<string, unknown>>({})
|
||||||
const lastLoadedAt = ref('')
|
const lastLoadedAt = ref('')
|
||||||
|
|
||||||
|
/** 微信小窗流程类型:授权 / 代注册 */
|
||||||
|
type WeChatFlowKind = 'auth' | 'register'
|
||||||
|
|
||||||
/** 授权小窗句柄与轮询计时器 */
|
/** 授权小窗句柄与轮询计时器 */
|
||||||
let authWindow: Window | null = null
|
let authWindow: Window | null = null
|
||||||
let authWatchTimer: number | null = null
|
let authWatchTimer: number | null = null
|
||||||
let authWatchStartedAt = 0
|
let authWatchStartedAt = 0
|
||||||
let authWatchBusy = false
|
let authWatchBusy = false
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// 域名限制:微信小程序授权页只能从主域名进入
|
||||||
|
// ============================================================
|
||||||
|
/** 当前访问域名(去协议/端口/路径,小写) */
|
||||||
|
const currentHost = normalizeFrontHost(window.location.hostname)
|
||||||
|
/** 是否主域名(= 品牌豁免域名 VITE_FRONT_CONFIG_EXEMPT_HOSTS,与 frontBrand 同源) */
|
||||||
|
const isMainDomain = isMainDomainHost(currentHost)
|
||||||
|
/** 非主域名时的提示文案 */
|
||||||
|
const mainDomainTip = `微信小程序授权只能从主域名进入(当前域名:${currentHost || '未知'})`
|
||||||
|
|
||||||
// ============================================================
|
// ============================================================
|
||||||
// 取值 / 归一化
|
// 取值 / 归一化
|
||||||
// ============================================================
|
// ============================================================
|
||||||
@ -298,48 +535,93 @@ const mappedKeys = computed(() => {
|
|||||||
function buildItem(def: FieldDefinition, key: string, rawValue: unknown): DisplayItem {
|
function buildItem(def: FieldDefinition, key: string, rawValue: unknown): DisplayItem {
|
||||||
const rawText = toDisplayText(rawValue)
|
const rawText = toDisplayText(rawValue)
|
||||||
const mappedText = def.valueMap ? (def.valueMap[rawText] ?? rawText) : rawText
|
const mappedText = def.valueMap ? (def.valueMap[rawText] ?? rawText) : rawText
|
||||||
const displayText = formatDateTimeValue(mappedText)
|
const displayText = formatDateTimeValue(key, mappedText)
|
||||||
const isSecret = SECRET_KEY_PATTERN.test(key)
|
const isSecret = SECRET_KEY_PATTERN.test(key)
|
||||||
const isImage = IMAGE_KEY_PATTERN.test(key) && /^https?:\/\//i.test(rawText)
|
const isImage = IMAGE_KEY_PATTERN.test(key) && /^https?:\/\//i.test(rawText)
|
||||||
const isStatus = Boolean(def.tag)
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
key,
|
key,
|
||||||
label: def.label,
|
label: def.label,
|
||||||
value: isSecret ? maskSecret(displayText) : displayText,
|
value: isSecret ? maskSecret(displayText) : displayText,
|
||||||
wide: def.wide,
|
imageSrc: isImage ? normalizeImageUrl(rawText) : '',
|
||||||
isImage,
|
isImage,
|
||||||
isSecret,
|
isSecret,
|
||||||
isStatus,
|
isFuncInfo: key === 'func_info'
|
||||||
statusType: resolveStatusType(rawText, mappedText)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** ISO 时间(2026-09-21T18:14:44.000Z)统一展示为本地 YYYY-MM-DD HH:mm:ss */
|
/** 图片地址归一化:页面为 https 时把 http 图片改走 https,避免混合内容被浏览器拦截(如微信头像 CDN) */
|
||||||
function formatDateTimeValue(text: string): string {
|
function normalizeImageUrl(raw: string): string {
|
||||||
if (!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/.test(text)) return text
|
if (window.location.protocol === 'https:' && /^http:\/\//i.test(raw)) {
|
||||||
const date = new Date(text)
|
return raw.replace(/^http:\/\//i, 'https://')
|
||||||
if (Number.isNaN(date.getTime())) return text
|
}
|
||||||
|
return raw
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 本地时间格式化为 YYYY-MM-DD HH:mm:ss */
|
||||||
|
function toLocalDateTime(date: Date): string {
|
||||||
const pad = (num: number) => String(num).padStart(2, '0')
|
const pad = (num: number) => String(num).padStart(2, '0')
|
||||||
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`
|
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
/** 状态类标签颜色(先看翻译后的中文,再看原值) */
|
* 时间展示:ISO 字符串(2026-09-21T11:14:03.000Z)始终转换;
|
||||||
function resolveStatusType(rawText: string, mappedText: string): DisplayItem['statusType'] {
|
* Unix 时间戳(10 位=秒、13 位=毫秒,如 auth_time: 1789989241)仅在时间类字段上转换,避免 ID 被误判
|
||||||
const text = mappedText || rawText
|
*/
|
||||||
if (/停用|禁用|失败|异常|无效|过期|未授权|false|^0$/i.test(text)) return 'danger'
|
function formatDateTimeValue(key: string, text: string): string {
|
||||||
if (/启用|正常|成功|已授权|是|true|^1$/i.test(text)) return 'success'
|
if (!text) return text
|
||||||
return 'info'
|
if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/.test(text)) {
|
||||||
|
const date = new Date(text)
|
||||||
|
return Number.isNaN(date.getTime()) ? text : toLocalDateTime(date)
|
||||||
|
}
|
||||||
|
if (/(time|_at$|date)/i.test(key)) {
|
||||||
|
if (/^\d{10}$/.test(text)) return toLocalDateTime(new Date(Number(text) * 1000))
|
||||||
|
if (/^\d{13}$/.test(text)) return toLocalDateTime(new Date(Number(text)))
|
||||||
|
}
|
||||||
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 已知字段展示项 */
|
/**
|
||||||
|
* 授权功能集:func_info 为 JSON 字符串,形如
|
||||||
|
* [{"funcscope_category":{"id":17}},{"funcscope_category":{"id":25},"confirm_info":{...}}]
|
||||||
|
* 解析后逐项展示(功能名称由后端注册表提供时再补充,此处仅展示功能 ID 与需确认标记)
|
||||||
|
*/
|
||||||
|
const funcInfoItems = computed<FuncInfoItem[]>(() => {
|
||||||
|
const raw = config.value.func_info
|
||||||
|
const text = typeof raw === 'string' ? raw.trim() : raw ? JSON.stringify(raw) : ''
|
||||||
|
if (!text) return []
|
||||||
|
try {
|
||||||
|
const parsed: unknown = JSON.parse(text)
|
||||||
|
if (!Array.isArray(parsed)) return []
|
||||||
|
return parsed.map((entry: any) => {
|
||||||
|
const id = entry?.funcscope_category?.id ?? entry?.id ?? '-'
|
||||||
|
const needConfirm = Number(entry?.confirm_info?.need_confirm) === 1
|
||||||
|
return {
|
||||||
|
id: String(id),
|
||||||
|
label: needConfirm ? `功能 ${id}(需确认)` : `功能 ${id}`,
|
||||||
|
raw: JSON.stringify(entry)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} catch {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
/** 已知字段展示项(hidden 字段不展示,但仍消耗掉对应 key) */
|
||||||
const infoItems = computed<DisplayItem[]>(() => {
|
const infoItems = computed<DisplayItem[]>(() => {
|
||||||
const items: DisplayItem[] = []
|
const items: DisplayItem[] = []
|
||||||
for (const def of FIELD_DEFINITIONS) {
|
for (const def of FIELD_DEFINITIONS) {
|
||||||
|
if (def.hidden) continue
|
||||||
const hit = def.keys.find((key) => !isEmptyValue(config.value[key]))
|
const hit = def.keys.find((key) => !isEmptyValue(config.value[key]))
|
||||||
if (!hit) continue
|
if (!hit) continue
|
||||||
items.push(buildItem(def, hit, config.value[hit]))
|
items.push(buildItem(def, hit, config.value[hit]))
|
||||||
}
|
}
|
||||||
|
// 授权功能集:可解析时用摘要替换原始 JSON,明细由下方功能项标签展示
|
||||||
|
const funcItem = items.find((item) => item.isFuncInfo)
|
||||||
|
if (funcItem && funcInfoItems.value.length) {
|
||||||
|
funcItem.value = `共 ${funcInfoItems.value.length} 项:${funcInfoItems.value
|
||||||
|
.map((fn) => fn.id)
|
||||||
|
.join('、')}`
|
||||||
|
}
|
||||||
return items
|
return items
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -347,13 +629,7 @@ const infoItems = computed<DisplayItem[]>(() => {
|
|||||||
const otherItems = computed<DisplayItem[]>(() =>
|
const otherItems = computed<DisplayItem[]>(() =>
|
||||||
entries.value
|
entries.value
|
||||||
.filter(([key]) => !mappedKeys.value.has(key))
|
.filter(([key]) => !mappedKeys.value.has(key))
|
||||||
.map(([key, value]) =>
|
.map(([key, value]) => buildItem({ label: key, keys: [key] }, key, value))
|
||||||
buildItem(
|
|
||||||
{ label: key, keys: [key], wide: toDisplayText(value).length > 60 },
|
|
||||||
key,
|
|
||||||
value
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ============================================================
|
// ============================================================
|
||||||
@ -387,8 +663,8 @@ async function loadConfig(options: { silent?: boolean } = {}) {
|
|||||||
// ============================================================
|
// ============================================================
|
||||||
// 授权(点击按钮后才获取链接并弹小窗)
|
// 授权(点击按钮后才获取链接并弹小窗)
|
||||||
// ============================================================
|
// ============================================================
|
||||||
/** 从响应中取授权链接(字段名多形态兼容,兜底扫描 http 开头的字符串) */
|
/** 从响应中取链接(字段名多形态兼容,兜底扫描 http 开头的字符串):授权链接与代注册链接共用 */
|
||||||
function pickAuthUrl(raw: Record<string, unknown>): string {
|
function pickUrl(raw: Record<string, unknown>): string {
|
||||||
for (const key of AUTH_URL_KEYS) {
|
for (const key of AUTH_URL_KEYS) {
|
||||||
const value = raw[key]
|
const value = raw[key]
|
||||||
if (typeof value === 'string' && /^https?:\/\//i.test(value.trim())) return value.trim()
|
if (typeof value === 'string' && /^https?:\/\//i.test(value.trim())) return value.trim()
|
||||||
@ -399,25 +675,29 @@ function pickAuthUrl(raw: Record<string, unknown>): string {
|
|||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 在新小窗口中打开授权链接 */
|
/** 在新小窗口中打开链接(授权 / 代注册共用) */
|
||||||
function openAuthWindow(url: string) {
|
function openSmallWindow(url: string, windowName: string, tipText: string, kind: WeChatFlowKind) {
|
||||||
const width = 760
|
const width = 760
|
||||||
const height = 780
|
const height = 780
|
||||||
const left = Math.max(0, Math.round((window.screen.width - width) / 2))
|
const left = Math.max(0, Math.round((window.screen.width - width) / 2))
|
||||||
const top = Math.max(0, Math.round((window.screen.height - height) / 2))
|
const top = Math.max(0, Math.round((window.screen.height - height) / 2))
|
||||||
const features = `width=${width},height=${height},left=${left},top=${top},resizable=yes,scrollbars=yes`
|
const features = `width=${width},height=${height},left=${left},top=${top},resizable=yes,scrollbars=yes`
|
||||||
|
|
||||||
authWindow = window.open(url, 'wx-miniprogram-authorize', features)
|
authWindow = window.open(url, windowName, features)
|
||||||
if (!authWindow) {
|
if (!authWindow) {
|
||||||
ElMessage.warning('授权窗口被浏览器拦截:请允许本站弹出窗口后重试')
|
ElMessage.warning('窗口被浏览器拦截:请允许本站弹出窗口后重试')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ElMessage.info('请在新打开的小窗口中完成微信授权,完成后本页会自动刷新')
|
ElMessage.info(tipText)
|
||||||
startAuthWatch()
|
startWatch(kind)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 点击「去授权」:获取授权链接 → 打开小窗 */
|
/** 点击「去授权」:获取授权链接 → 打开小窗(仅主域名可用) */
|
||||||
async function handleAuthorize() {
|
async function handleAuthorize() {
|
||||||
|
if (!isMainDomain) {
|
||||||
|
ElMessage.warning(mainDomainTip)
|
||||||
|
return
|
||||||
|
}
|
||||||
authUrlLoading.value = true
|
authUrlLoading.value = true
|
||||||
try {
|
try {
|
||||||
const res: any = await wechatGetAuthUrl()
|
const res: any = await wechatGetAuthUrl()
|
||||||
@ -425,12 +705,12 @@ async function handleAuthorize() {
|
|||||||
ElMessage.error(res?.message || '获取微信授权链接失败')
|
ElMessage.error(res?.message || '获取微信授权链接失败')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const url = pickAuthUrl({ ...unwrapSettingWarehousePayload(res) })
|
const url = pickUrl({ ...unwrapSettingWarehousePayload(res) })
|
||||||
if (!url) {
|
if (!url) {
|
||||||
ElMessage.error('未获取到授权链接,请稍后重试')
|
ElMessage.error('未获取到授权链接,请稍后重试')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
openAuthWindow(url)
|
openSmallWindow(url, 'wx-miniprogram-authorize', '请在新打开的小窗口中完成微信授权,完成后本页会自动刷新', 'auth')
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
ElMessage.error(e instanceof Error ? e.message : '获取微信授权链接失败')
|
ElMessage.error(e instanceof Error ? e.message : '获取微信授权链接失败')
|
||||||
} finally {
|
} finally {
|
||||||
@ -438,8 +718,34 @@ async function handleAuthorize() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 授权小窗打开期间轮询配置:授权完成即自动刷新 */
|
/** 点击「代注册小程序」:获取代注册链接 → 打开小窗(仅主域名可用) */
|
||||||
function startAuthWatch() {
|
async function handleRegister() {
|
||||||
|
if (!isMainDomain) {
|
||||||
|
ElMessage.warning(mainDomainTip)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
registerUrlLoading.value = true
|
||||||
|
try {
|
||||||
|
const res: any = await wechatGetRegisterUrl()
|
||||||
|
if (!res || !okCode(res.code)) {
|
||||||
|
ElMessage.error(res?.message || '获取代注册链接失败')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const url = pickUrl({ ...unwrapSettingWarehousePayload(res) })
|
||||||
|
if (!url) {
|
||||||
|
ElMessage.error('未获取到代注册链接,请稍后重试')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
openSmallWindow(url, 'wx-miniprogram-register', '请在新打开的小窗口中完成小程序代注册,完成后本页会自动刷新', 'register')
|
||||||
|
} catch (e: unknown) {
|
||||||
|
ElMessage.error(e instanceof Error ? e.message : '获取代注册链接失败')
|
||||||
|
} finally {
|
||||||
|
registerUrlLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 小窗打开期间轮询配置:流程完成即自动刷新 */
|
||||||
|
function startWatch(kind: WeChatFlowKind) {
|
||||||
stopAuthWatch()
|
stopAuthWatch()
|
||||||
authWatchStartedAt = Date.now()
|
authWatchStartedAt = Date.now()
|
||||||
authWatchTimer = window.setInterval(async () => {
|
authWatchTimer = window.setInterval(async () => {
|
||||||
@ -460,7 +766,7 @@ function startAuthWatch() {
|
|||||||
const payload = await loadConfig({ silent: true })
|
const payload = await loadConfig({ silent: true })
|
||||||
if (payload && Object.entries(payload).some(([key, value]) => !NEUTRAL_KEYS.has(key.toLowerCase()) && !isEmptyValue(value))) {
|
if (payload && Object.entries(payload).some(([key, value]) => !NEUTRAL_KEYS.has(key.toLowerCase()) && !isEmptyValue(value))) {
|
||||||
stopAuthWatch()
|
stopAuthWatch()
|
||||||
ElMessage.success('微信小程序授权成功,配置已刷新')
|
ElMessage.success(kind === 'register' ? '小程序代注册完成,配置已刷新' : '微信小程序授权成功,配置已刷新')
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
authWatchBusy = false
|
authWatchBusy = false
|
||||||
@ -501,7 +807,12 @@ onBeforeUnmount(() => {
|
|||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.mp-config-page {
|
.mp-config-page {
|
||||||
padding: 12px 16px 24px;
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
flex: 1;
|
||||||
|
height: 100%;
|
||||||
|
min-height: 0;
|
||||||
|
padding: 12px 16px 16px;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
background: #fff;
|
background: #fff;
|
||||||
}
|
}
|
||||||
@ -537,11 +848,18 @@ onBeforeUnmount(() => {
|
|||||||
gap: 8px;
|
gap: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 禁用按钮外包一层,保证 tooltip 在 disabled 状态下仍可触发 */
|
||||||
|
.mp-auth-trigger {
|
||||||
|
display: inline-flex;
|
||||||
|
}
|
||||||
|
|
||||||
.mp-config-alert {
|
.mp-config-alert {
|
||||||
|
flex-shrink: 0;
|
||||||
margin-bottom: 16px;
|
margin-bottom: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.mp-empty {
|
.mp-empty {
|
||||||
|
flex-shrink: 0;
|
||||||
border: 1px solid #ebeef5;
|
border: 1px solid #ebeef5;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
padding: 24px 16px;
|
padding: 24px 16px;
|
||||||
@ -574,32 +892,208 @@ onBeforeUnmount(() => {
|
|||||||
line-height: 18px;
|
line-height: 18px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.mp-descriptions {
|
/* ===== 基础信息 / 其他信息:名称 + 不可编辑输入框 ===== */
|
||||||
|
.mp-info-form {
|
||||||
max-width: 900px;
|
max-width: 900px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.mp-value {
|
.mp-info-form :deep(.el-form-item) {
|
||||||
|
margin-bottom: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mp-field-row {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 8px;
|
gap: 8px;
|
||||||
min-width: 0;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.mp-value__text {
|
.mp-field {
|
||||||
|
max-width: 560px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 禁用态下保持可读文字颜色(只读展示) */
|
||||||
|
.mp-field :deep(.el-input__inner) {
|
||||||
|
color: #303133;
|
||||||
|
-webkit-text-fill-color: #303133;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mp-thumb {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
width: 56px;
|
||||||
|
height: 56px;
|
||||||
|
border-radius: 6px;
|
||||||
|
background: #f5f7fa;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mp-thumb__tip {
|
||||||
|
font-size: 12px;
|
||||||
|
color: #c0c4cc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 授权功能集:解析后的功能项标签 */
|
||||||
|
.mp-func-list {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 6px;
|
||||||
|
margin-top: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mp-func-tag {
|
||||||
|
cursor: default;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ===== 已授权:左菜单 + 右明细(均铺满高度) ===== */
|
||||||
|
.mp-layout {
|
||||||
|
flex: 1;
|
||||||
|
min-height: 0;
|
||||||
|
display: flex;
|
||||||
|
align-items: stretch;
|
||||||
|
gap: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 左侧菜单:竖向铺满到底,菜单过长时自身上下滚动 */
|
||||||
|
.mp-nav {
|
||||||
|
flex: 0 0 200px;
|
||||||
|
min-height: 0;
|
||||||
|
padding: 8px;
|
||||||
|
border: 1px solid #e8eef7;
|
||||||
|
border-radius: 6px;
|
||||||
|
background: #f8fbff;
|
||||||
|
box-sizing: border-box;
|
||||||
|
overflow-y: auto;
|
||||||
|
overscroll-behavior: contain;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mp-nav__list {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 4px;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
list-style: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mp-nav__item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
height: 38px;
|
||||||
|
padding: 0 10px;
|
||||||
|
border-radius: 6px;
|
||||||
|
font-size: 14px;
|
||||||
|
color: #606266;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
color: #409eff;
|
||||||
|
background: rgba(64, 158, 255, 0.06);
|
||||||
|
}
|
||||||
|
|
||||||
|
&.is-active {
|
||||||
|
color: #409eff;
|
||||||
|
font-weight: 600;
|
||||||
|
background: #fff;
|
||||||
|
box-shadow: inset 0 0 0 1px #e8eef7;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.mp-nav__icon {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mp-nav__label {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.mp-value__image {
|
.mp-nav__tag {
|
||||||
width: 48px;
|
flex: 0 0 auto;
|
||||||
height: 48px;
|
|
||||||
border-radius: 4px;
|
|
||||||
background: #f5f7fa;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.mp-value__tip {
|
/* 右侧明细:边框铺满到底,内容过长时自身上下滚动 */
|
||||||
|
.mp-detail {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
min-height: 0;
|
||||||
|
padding: 12px 16px;
|
||||||
|
border: 1px solid #e8eef7;
|
||||||
|
border-radius: 6px;
|
||||||
|
background: #fff;
|
||||||
|
box-sizing: border-box;
|
||||||
|
overflow-y: auto;
|
||||||
|
overscroll-behavior: contain;
|
||||||
|
|
||||||
|
> :last-child {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 右侧本身就是带边框的容器,内部面板不再重复描边(避免“多一个框”) */
|
||||||
|
.mp-panel {
|
||||||
|
padding: 0;
|
||||||
|
border: none;
|
||||||
|
border-radius: 0;
|
||||||
|
background: transparent;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.mp-placeholder {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mp-placeholder__block {
|
||||||
|
flex: 1 1 240px;
|
||||||
|
min-width: 220px;
|
||||||
|
padding: 12px;
|
||||||
|
border: 1px dashed #d9e4f2;
|
||||||
|
border-radius: 6px;
|
||||||
|
background: #fbfdff;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mp-placeholder__title {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #303133;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mp-placeholder__desc {
|
||||||
|
margin: 6px 0 0;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
color: #c0c4cc;
|
color: #909399;
|
||||||
|
line-height: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 900px) {
|
||||||
|
.mp-layout {
|
||||||
|
flex-direction: column;
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mp-nav {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
width: 100%;
|
||||||
|
overflow-y: visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mp-nav__list {
|
||||||
|
flex-direction: row;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mp-detail {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
overflow-y: visible;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user