1
This commit is contained in:
parent
33756ce1fd
commit
e54e3e7745
@ -24,7 +24,6 @@ export function shopsList(data?: {
|
||||
export function shopsAdd(data: {
|
||||
platform_code: string
|
||||
custom_name: string
|
||||
shop_name?: string
|
||||
}) {
|
||||
return request({
|
||||
url: '/system',
|
||||
@ -79,7 +78,7 @@ export function shopGetAuthorizeSessionKey(data: {
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
params: {
|
||||
method: 'shop.GetAuthorizeSessionKey',
|
||||
method: 'shops.GetAuthorizeSessionKey',
|
||||
v,
|
||||
timestamp: new Date().getTime()
|
||||
},
|
||||
|
||||
@ -29,8 +29,8 @@
|
||||
style="width: 120px"
|
||||
@change="handleFilter"
|
||||
>
|
||||
<el-option label="正常" value="ACTIVE" />
|
||||
<el-option label="停用" value="INACTIVE" />
|
||||
<el-option label="已激活" value="1" />
|
||||
<el-option label="未激活" value="0" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="关键词">
|
||||
@ -44,6 +44,7 @@
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" :loading="loading" @click="handleFilter">搜索</el-button>
|
||||
<el-button :loading="loading" @click="handleResetFilters">重置条件</el-button>
|
||||
<el-button :loading="loading" @click="loadList">刷新</el-button>
|
||||
<el-button type="success" @click="openCreate">新增店铺</el-button>
|
||||
</el-form-item>
|
||||
@ -68,6 +69,12 @@
|
||||
@page-size-change="handlePageSizeChange"
|
||||
@refresh="loadList"
|
||||
>
|
||||
<template #column-auth_expire_at="{ row }">
|
||||
<el-tag :type="isAuthExpired(row.auth_expire_at) ? 'danger' : 'info'" size="small">
|
||||
{{ formatAuthExpireAt(row.auth_expire_at) }}
|
||||
</el-tag>
|
||||
</template>
|
||||
|
||||
<template #column-status="{ row }">
|
||||
<el-tag :type="formatShopStatus(row.status).type" size="small">
|
||||
{{ formatShopStatus(row.status).text }}
|
||||
@ -113,14 +120,6 @@
|
||||
<el-form-item label="自定义名称" prop="custom_name">
|
||||
<el-input v-model="formData.custom_name" placeholder="最大 100 字符" maxlength="100" show-word-limit />
|
||||
</el-form-item>
|
||||
<el-form-item v-if="dialogMode === 'create'" label="店铺名称">
|
||||
<el-input
|
||||
v-model="formData.shop_name"
|
||||
placeholder="可选,不填则使用自定义名称"
|
||||
maxlength="100"
|
||||
show-word-limit
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="dialogVisible = false">取消</el-button>
|
||||
@ -139,12 +138,20 @@
|
||||
<el-form-item label="店铺">
|
||||
<el-input :model-value="authForm.shopLabel" disabled />
|
||||
</el-form-item>
|
||||
<el-form-item label="平台">
|
||||
<el-input :model-value="authForm.platform_name || authForm.platformCode || '--'" disabled />
|
||||
</el-form-item>
|
||||
<el-form-item label="回调地址" prop="callbackurl">
|
||||
<el-input
|
||||
v-model="authForm.callbackurl"
|
||||
placeholder="请输入授权完成后的回调 URL"
|
||||
clearable
|
||||
/>
|
||||
<div class="callback-input-row">
|
||||
<el-button type="primary" plain :loading="authSubmitting" @click="handleOpenAuthorizeLink">
|
||||
去授权
|
||||
</el-button>
|
||||
<el-input
|
||||
v-model="authForm.callbackurl"
|
||||
placeholder="请输入授权完成后的回调 URL"
|
||||
clearable
|
||||
/>
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
@ -160,6 +167,7 @@ import { onMounted, reactive, ref } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
import UpperTable from '@/components/UpperTable/index.vue'
|
||||
import { getPlatformOauthLink } from '@/api/index/index'
|
||||
import { getPrintPlatformList } from '@/api/setting.expressinterface/expressInterface'
|
||||
import {
|
||||
shopGetAuthorizeSessionKey,
|
||||
@ -206,8 +214,7 @@ const formRef = ref<FormInstance>()
|
||||
const formData = reactive({
|
||||
id: undefined as number | undefined,
|
||||
platform_code: '',
|
||||
custom_name: '',
|
||||
shop_name: ''
|
||||
custom_name: ''
|
||||
})
|
||||
|
||||
const rules: FormRules = {
|
||||
@ -221,6 +228,8 @@ const rules: FormRules = {
|
||||
const authForm = reactive({
|
||||
shopId: undefined as number | undefined,
|
||||
shopLabel: '',
|
||||
platform_name: '',
|
||||
platformCode: '',
|
||||
callbackurl: ''
|
||||
})
|
||||
|
||||
@ -230,6 +239,39 @@ const authRules: FormRules = {
|
||||
|
||||
const isSuccess = (res: any) => res && [0, 1, 200].includes(res.code)
|
||||
|
||||
function parseAuthExpireAt(value: unknown): number | null {
|
||||
if (value === null || value === undefined || value === '') return null
|
||||
if (typeof value === 'number' && Number.isFinite(value)) {
|
||||
return value > 1e12 ? value : value * 1000
|
||||
}
|
||||
const raw = String(value).trim()
|
||||
if (!raw) return null
|
||||
if (/^\d+$/.test(raw)) {
|
||||
const num = Number(raw)
|
||||
if (!Number.isFinite(num)) return null
|
||||
return num > 1e12 ? num : num * 1000
|
||||
}
|
||||
const ts = new Date(raw).getTime()
|
||||
return Number.isFinite(ts) ? ts : null
|
||||
}
|
||||
|
||||
function formatAuthExpireAt(value: unknown): string {
|
||||
const ts = parseAuthExpireAt(value)
|
||||
if (ts === null) {
|
||||
const text = String(value ?? '').trim()
|
||||
return text || '--'
|
||||
}
|
||||
const d = new Date(ts)
|
||||
const pad = (n: number) => String(n).padStart(2, '0')
|
||||
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`
|
||||
}
|
||||
|
||||
function isAuthExpired(value: unknown): boolean {
|
||||
const ts = parseAuthExpireAt(value)
|
||||
if (ts === null) return false
|
||||
return ts < Date.now()
|
||||
}
|
||||
|
||||
async function loadList() {
|
||||
loading.value = true
|
||||
const start = Date.now()
|
||||
@ -295,11 +337,18 @@ function handleFilter() {
|
||||
loadList()
|
||||
}
|
||||
|
||||
function handleResetFilters() {
|
||||
listQuery.platform_code = ''
|
||||
listQuery.status = ''
|
||||
listQuery.keyword = ''
|
||||
pagination.currentPage = 1
|
||||
loadList()
|
||||
}
|
||||
|
||||
function resetForm() {
|
||||
formData.id = undefined
|
||||
formData.platform_code = ''
|
||||
formData.custom_name = ''
|
||||
formData.shop_name = ''
|
||||
formRef.value?.clearValidate()
|
||||
}
|
||||
|
||||
@ -316,7 +365,6 @@ function openEdit(row: ShopRecord) {
|
||||
formData.id = row.id
|
||||
formData.platform_code = row.platform_code || ''
|
||||
formData.custom_name = row.custom_name || ''
|
||||
formData.shop_name = ''
|
||||
formRef.value?.clearValidate()
|
||||
}
|
||||
|
||||
@ -331,13 +379,10 @@ async function submitForm() {
|
||||
const payload: {
|
||||
platform_code: string
|
||||
custom_name: string
|
||||
shop_name?: string
|
||||
} = {
|
||||
platform_code: formData.platform_code,
|
||||
custom_name: formData.custom_name.trim()
|
||||
}
|
||||
const shopName = formData.shop_name.trim()
|
||||
if (shopName) payload.shop_name = shopName
|
||||
|
||||
const res: any = await shopsAdd(payload)
|
||||
if (!isSuccess(res)) {
|
||||
@ -380,7 +425,7 @@ async function submitForm() {
|
||||
function handleDelete(row: ShopRecord) {
|
||||
if (!row.id) return
|
||||
const name = row.custom_name || row.shop_name || String(row.id)
|
||||
ElMessageBox.confirm(`确认删除店铺「${name}」吗?`, '提示', { type: 'warning' })
|
||||
ElMessageBox.confirm(`确认删除店铺「${name}」吗?删除后相关快递接口将不可用`, '提示', { type: 'warning' })
|
||||
.then(async () => {
|
||||
const res: any = await shopsDel({ id: row.id as number })
|
||||
if (!isSuccess(res)) {
|
||||
@ -399,6 +444,8 @@ function handleDelete(row: ShopRecord) {
|
||||
function resetAuthForm() {
|
||||
authForm.shopId = undefined
|
||||
authForm.shopLabel = ''
|
||||
authForm.platform_name = ''
|
||||
authForm.platformCode = ''
|
||||
authForm.callbackurl = ''
|
||||
authFormRef.value?.clearValidate()
|
||||
}
|
||||
@ -407,6 +454,8 @@ function openAuthorize(row: ShopRecord) {
|
||||
if (!row.id) return
|
||||
authForm.shopId = row.id
|
||||
authForm.shopLabel = row.custom_name || row.shop_name || String(row.id)
|
||||
authForm.platform_name = String(row.platform_name || '').trim()
|
||||
authForm.platformCode = String(row.platform_code || '').trim()
|
||||
authForm.callbackurl = ''
|
||||
authDialogVisible.value = true
|
||||
authFormRef.value?.clearValidate()
|
||||
@ -417,10 +466,19 @@ async function submitAuthorize() {
|
||||
const valid = await authFormRef.value.validate().catch(() => false)
|
||||
if (!valid) return
|
||||
|
||||
const callbackurl = authForm.callbackurl.trim()
|
||||
const opened = await openShopAuthorizeInNewTab()
|
||||
if (opened) {
|
||||
authDialogVisible.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function openShopAuthorizeInNewTab() {
|
||||
if (authSubmitting.value || !authForm.shopId) return false
|
||||
|
||||
const callbackurl = String(authForm.callbackurl || '').trim()
|
||||
if (!callbackurl) {
|
||||
ElMessage.warning('请输入回调地址')
|
||||
return
|
||||
return false
|
||||
}
|
||||
|
||||
authSubmitting.value = true
|
||||
@ -431,25 +489,83 @@ async function submitAuthorize() {
|
||||
})
|
||||
if (!isSuccess(res)) {
|
||||
ElMessage.error(res?.message || '获取授权链接失败')
|
||||
return
|
||||
return false
|
||||
}
|
||||
const oauthUrl = String(res?.data?.authorize_url || '').trim()
|
||||
if (!oauthUrl) {
|
||||
ElMessage.error('未获取到有效的授权链接')
|
||||
return
|
||||
return false
|
||||
}
|
||||
authDialogVisible.value = false
|
||||
const win = window.open(oauthUrl, '_blank')
|
||||
if (!win) {
|
||||
window.location.href = oauthUrl
|
||||
}
|
||||
return true
|
||||
} catch {
|
||||
ElMessage.error('获取授权链接失败')
|
||||
return false
|
||||
} finally {
|
||||
authSubmitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function openAuthorizeInNewTab() {
|
||||
if (authSubmitting.value || !authForm.shopId) return false
|
||||
|
||||
const platformCode = String(authForm.platformCode || '').trim()
|
||||
if (!platformCode) {
|
||||
ElMessage.warning('未获取到店铺所属平台,无法发起授权')
|
||||
return false
|
||||
}
|
||||
|
||||
authSubmitting.value = true
|
||||
try {
|
||||
const res: any = await getPlatformOauthLink({
|
||||
code: platformCode,
|
||||
platform_code: platformCode,
|
||||
platformCode
|
||||
})
|
||||
if (!isSuccess(res)) {
|
||||
ElMessage.error(res?.message || '获取授权链接失败')
|
||||
return false
|
||||
}
|
||||
const data = res?.data
|
||||
const oauthUrl =
|
||||
typeof data === 'string'
|
||||
? data.trim()
|
||||
: String(
|
||||
data?.url ||
|
||||
data?.link ||
|
||||
data?.oauth_link ||
|
||||
data?.authLink ||
|
||||
data?.oauth_url ||
|
||||
data?.oauthUrl ||
|
||||
data?.redirect_url ||
|
||||
data?.redirectUrl ||
|
||||
''
|
||||
).trim()
|
||||
if (!oauthUrl) {
|
||||
ElMessage.error('未获取到有效的授权链接')
|
||||
return false
|
||||
}
|
||||
const win = window.open(oauthUrl, '_blank')
|
||||
if (!win) {
|
||||
window.location.href = oauthUrl
|
||||
}
|
||||
return true
|
||||
} catch {
|
||||
ElMessage.error('获取授权链接失败')
|
||||
return false
|
||||
} finally {
|
||||
authSubmitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function handleOpenAuthorizeLink() {
|
||||
if (authSubmitting.value || !authForm.shopId) return
|
||||
await openAuthorizeInNewTab()
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await loadPlatformOptions()
|
||||
await loadList()
|
||||
@ -465,4 +581,20 @@ onMounted(async () => {
|
||||
margin-right: 12px;
|
||||
}
|
||||
}
|
||||
|
||||
.callback-input-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.callback-input-row .el-button {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.callback-input-row .el-input {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
@ -4,6 +4,7 @@ export type ShopRecord = {
|
||||
platform_name?: string
|
||||
custom_name?: string
|
||||
shop_name?: string
|
||||
auth_expire_at?: string | number
|
||||
status?: string | number
|
||||
}
|
||||
|
||||
@ -13,6 +14,7 @@ export const shopColumns = [
|
||||
{ prop: 'platform_name', label: '平台名称', minWidth: '140', showOverflowTooltip: true },
|
||||
{ prop: 'custom_name', label: '自定义名称', minWidth: '160', showOverflowTooltip: true },
|
||||
{ prop: 'shop_name', label: '店铺名称', minWidth: '160', showOverflowTooltip: true },
|
||||
{ prop: 'auth_expire_at', label: '授权过期时间', minWidth: '180', align: 'center' },
|
||||
{ prop: 'status', label: '状态', width: '100', align: 'center' },
|
||||
{ prop: 'actions', label: '操作', width: '220', align: 'center', fixed: 'right' }
|
||||
]
|
||||
@ -21,10 +23,10 @@ export function formatShopStatus(status: string | number | undefined) {
|
||||
const raw = String(status ?? '').trim().toUpperCase()
|
||||
if (!raw) return { text: '--', type: 'info' as const }
|
||||
if (['1', 'ACTIVE', 'ENABLED', 'ENABLE'].includes(raw)) {
|
||||
return { text: '正常', type: 'success' as const }
|
||||
return { text: '已激活', type: 'success' as const }
|
||||
}
|
||||
if (['0', 'INACTIVE', 'DISABLED', 'DISABLE'].includes(raw)) {
|
||||
return { text: '停用', type: 'danger' as const }
|
||||
return { text: '未激活', type: 'info' as const }
|
||||
}
|
||||
return { text: String(status), type: 'info' as const }
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user