Files
JayuCloud/FD-Frontend/src/views/admin/ShopsView.vue
T

2784 lines
104 KiB
Vue
Raw Normal View History

2026-02-25 10:37:16 +08:00
<template>
<div class="shops">
<a-page-header v-if="!isMobile" title="店铺管理" sub-title="管理美甲店铺" />
<section v-else class="admin-page-intro">
<span class="admin-page-intro__eyebrow">经营</span>
<h1 class="admin-page-intro__title">店铺管理</h1>
<p class="admin-page-intro__subtitle">
移动端优先展示 Banner、营业时间、地址和启停状态,让店铺信息在手机上也能完整维护。
</p>
<div class="admin-page-intro__meta">
<span class="admin-page-chip">店铺 {{ shopList.length }}</span>
</div>
</section>
2026-02-25 10:37:16 +08:00
<a-card :bordered="false">
<template #title v-if="isMobile">
店铺列表
</template>
2026-02-25 10:37:16 +08:00
<template #extra>
<div class="admin-toolbar" :class="{ 'admin-toolbar--stacked': isMobile }">
2026-02-25 10:37:16 +08:00
<a-input-search
v-model:value="searchText"
placeholder="搜索店铺名称"
:style="isMobile ? { width: '100%' } : { width: '250px' }"
2026-02-25 10:37:16 +08:00
@search="handleSearch"
/>
<a-button v-if="!isMobile && hasPermission('shop:create')" type="primary" @click="showAddModal">
2026-02-25 10:37:16 +08:00
<template #icon>
<PlusOutlined />
</template>
新增店铺
</a-button>
</div>
2026-02-25 10:37:16 +08:00
</template>
<a-table
v-if="!isMobile"
2026-02-25 10:37:16 +08:00
:columns="columns"
:data-source="shopList"
:loading="loading"
:pagination="pagination"
2026-05-29 13:30:56 +08:00
:scroll="{ x: 'max-content' }"
2026-02-25 10:37:16 +08:00
@change="handleTableChange"
row-key="id"
>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'image'">
2026-02-26 14:20:35 +08:00
<div class="shop-images">
<a-image
v-for="(url, index) in getShopImages(record)"
:key="index"
:width="50"
:height="50"
:src="url"
style="object-fit: cover; border-radius: 4px; margin-right: 4px;"
:preview="false"
/>
<a-image
v-if="getShopImages(record).length === 0"
:width="50"
:height="50"
:src="DEFAULT_SHOP_IMAGE"
style="object-fit: cover; border-radius: 4px;"
:preview="false"
/>
</div>
2026-02-25 10:37:16 +08:00
</template>
<template v-else-if="column.key === 'banner'">
<div class="shop-banner">
<a-image
v-for="(url, index) in getShopBannerImages(record)"
:key="index"
:width="80"
:height="40"
:src="url"
style="object-fit: cover; border-radius: 4px; margin-right: 4px;"
:preview="false"
/>
<span v-if="getShopBannerImages(record).length === 0" class="no-banner">暂无Banner</span>
</div>
</template>
<template v-else-if="column.key === 'status'">
<a-switch
:checked="record.status !== 0"
:disabled="!hasPermission('shop:edit') || !isAdmin"
checked-children="启用"
un-checked-children="停用"
@change="(checked: any) => handleStatusChange(record, checked === true)"
/>
</template>
<template v-else-if="column.key === 'authorization'">
<a-space direction="vertical" size="small">
<a-tag :color="record.authorizationExpired ? 'red' : 'green'">
{{ record.authorizationStatusText || (record.authorizationExpired ? '已到期' : '有效') }}
</a-tag>
<span>{{ formatAuthorizationExpireTime(record.authorizationExpireTime) }}</span>
</a-space>
</template>
<template v-else-if="column.key === 'shopName'">
<div style="max-width: 180px;">
<TableEllipsisText :text="record.shopName" />
</div>
</template>
<template v-else-if="column.key === 'description'">
<div style="max-width: 280px;">
<TableEllipsisText :text="record.description" :lines="2" />
</div>
</template>
<template v-else-if="column.key === 'address'">
<div style="max-width: 260px;">
<TableEllipsisText :text="record.address" :lines="2" />
</div>
</template>
<template v-else-if="column.key === 'businessHours'">
<div style="max-width: 140px;">
<TableEllipsisText :text="record.businessHours" />
</div>
</template>
2026-02-25 10:37:16 +08:00
<template v-else-if="column.key === 'actions'">
<a-space>
2026-02-28 14:32:28 +08:00
<a-button v-if="hasPermission('shop:view')" type="link" size="small" @click="showViewModal(record)">
查看
</a-button>
2026-02-26 22:51:56 +08:00
<a-button v-if="hasPermission('shop:edit')" type="link" size="small" @click="showEditModal(record)">
2026-02-25 10:37:16 +08:00
编辑
</a-button>
</a-space>
</template>
</template>
</a-table>
<AdminMobileCardList v-else :items="shopList" empty-description="暂无店铺数据">
<template #item="{ item }">
<article class="admin-mobile-card">
<a-image
class="admin-mobile-card__cover admin-mobile-card__cover--wide"
:src="getShopBannerImages(item)[0] || getShopImages(item)[0] || DEFAULT_SHOP_IMAGE"
:preview="false"
/>
<div class="admin-mobile-card__head" style="margin-top: 14px">
<div class="admin-mobile-card__body">
<div class="admin-mobile-card__title">{{ item.shopName }}</div>
<div class="admin-mobile-card__subtitle">{{ item.businessHours || '未设置营业时间' }}</div>
</div>
<a-tag :color="item.status !== 0 ? 'green' : 'default'">
{{ item.status !== 0 ? '启用' : '停用' }}
</a-tag>
</div>
<div class="admin-mobile-card__description">{{ item.description || '暂无店铺描述' }}</div>
<div class="admin-mobile-card__rows">
<div class="admin-mobile-card__row">
<span>地址</span>
<strong>{{ item.address || '--' }}</strong>
</div>
</div>
<div class="admin-mobile-card__actions">
<a-button size="small" @click="showViewModal(item)">查看</a-button>
<a-button v-if="hasPermission('shop:edit')" size="small" @click="showEditModal(item)">编辑</a-button>
2026-05-23 15:16:40 +08:00
<a-button
v-if="hasPermission('shop:edit')"
size="small"
:disabled="!isAdmin"
@click="handleStatusChange(item, item.status === 0)"
>
{{ item.status === 0 ? '启用' : '停用' }}
</a-button>
</div>
</article>
</template>
</AdminMobileCardList>
2026-02-25 10:37:16 +08:00
</a-card>
<AdminResponsiveModal
2026-02-25 10:37:16 +08:00
v-model:open="modalVisible"
:title="isEdit ? '编辑店铺' : '新增店铺'"
:desktop-width="700"
2026-02-25 10:37:16 +08:00
@ok="handleModalOk"
@cancel="handleModalCancel"
:confirmLoading="modalLoading"
2026-03-26 11:41:38 +08:00
:ok-button-props="{ disabled: isUploadPending }"
2026-02-25 10:37:16 +08:00
>
2026-03-26 12:04:02 +08:00
<DraftActions
:saved-at="draftSavedAt"
:disabled="isUploadPending"
@save="handleSaveDraft"
@clear="handleClearDraft"
/>
2026-02-25 10:37:16 +08:00
<a-form
ref="formRef"
:model="formState"
:rules="formRules"
:label-col="{ span: 5 }"
:wrapper-col="{ span: 18 }"
>
2026-02-25 14:44:50 +08:00
<a-form-item label="店铺名称" name="shopName">
<a-input v-model:value="formState.shopName" placeholder="请输入店铺名称" />
2026-02-25 10:37:16 +08:00
</a-form-item>
<a-form-item label="店铺描述" name="description">
<a-textarea
v-model:value="formState.description"
placeholder="请输入店铺描述"
:rows="3"
/>
</a-form-item>
<a-form-item label="店铺地址" name="address">
<a-input v-model:value="formState.address" placeholder="可手动输入,也可点击腾讯地图选点后自动回填" />
2026-02-25 10:37:16 +08:00
</a-form-item>
<a-form-item label="地图位置">
<div class="map-picker-card">
<div class="map-picker-main">
<div class="map-picker-title">{{ selectedLocationText }}</div>
<div class="map-picker-subtitle">{{ selectedCoordinateText }}</div>
</div>
<a-button @click="openMapLocationPicker">地图选点</a-button>
</div>
<div class="map-picker-tip">选点后会自动保存位置名称、地址和坐标;用户端展示地名,并支持腾讯地图和高德地图导航。</div>
</a-form-item>
2026-02-25 10:37:16 +08:00
<a-form-item label="营业时间" name="businessHours">
2026-03-21 13:16:39 +08:00
<div class="business-hours-picker">
<a-date-picker
v-model:value="businessStartTime"
picker="time"
popup-class-name="yumi-date-picker-panel yumi-time-panel"
2026-03-21 13:16:39 +08:00
value-format="HH:mm"
format="HH:mm"
placeholder="开始时间"
input-read-only
style="width: calc(50% - 14px)"
@change="handleBusinessHoursChange"
/>
<span class="business-hours-separator">至</span>
<a-date-picker
v-model:value="businessEndTime"
picker="time"
popup-class-name="yumi-date-picker-panel yumi-time-panel"
2026-03-21 13:16:39 +08:00
value-format="HH:mm"
format="HH:mm"
placeholder="结束时间"
input-read-only
style="width: calc(50% - 14px)"
@change="handleBusinessHoursChange"
/>
</div>
2026-02-25 10:37:16 +08:00
</a-form-item>
<a-form-item label="授权起始日" name="authorizationStartDate">
<a-date-picker
v-model:value="formState.authorizationStartDate"
value-format="YYYY-MM-DD"
format="YYYY-MM-DD"
placeholder="为空表示长期有效"
:disabled="!isAdmin"
style="width: 100%"
/>
</a-form-item>
<a-form-item label="有效期天数" name="authorizationDays">
<a-input-number
v-model:value="formState.authorizationDays"
:min="1"
:precision="0"
placeholder="例如 30"
:disabled="!isAdmin || !formState.authorizationStartDate"
style="width: 100%"
/>
</a-form-item>
<a-form-item label="到期时间">
<a-input :value="computedAuthorizationExpireTimeText" disabled />
</a-form-item>
<a-form-item label="Banner图片">
<div class="upload-tip">首页轮播图,建议尺寸 750x300 像素</div>
<a-upload
v-model:file-list="bannerFileList"
list-type="picture-card"
:custom-request="handleUploadBanner"
:before-upload="beforeUpload"
@preview="handleBannerPreview"
@remove="handleBannerRemove"
:max-count="5"
>
<div v-if="bannerFileList.length < 5">
<plus-outlined />
<div style="margin-top: 8px">上传Banner</div>
</div>
</a-upload>
2026-03-26 11:41:38 +08:00
<div v-if="isUploadPending" class="upload-pending-tip">图片正在上传中,上传完成前不可提交。</div>
2026-05-29 13:30:56 +08:00
<a-modal v-model:open="bannerPreviewVisible" :footer="null" :mask-closable="false" @cancel="bannerPreviewVisible = false">
<img alt="预览" style="width: 100%" :src="bannerPreviewImage" />
</a-modal>
</a-form-item>
2026-02-26 14:20:35 +08:00
<a-form-item label="店铺图片">
<div class="upload-tip">店铺详情展示图</div>
2026-02-26 14:20:35 +08:00
<a-upload
v-model:file-list="imageFileList"
list-type="picture-card"
:custom-request="handleUploadImage"
:before-upload="beforeUpload"
@preview="handlePreview"
@remove="handleRemove"
:max-count="5"
>
<div v-if="imageFileList.length < 5">
<plus-outlined />
<div style="margin-top: 8px">上传图片</div>
</div>
</a-upload>
2026-03-26 11:41:38 +08:00
<div v-if="isUploadPending" class="upload-pending-tip">图片正在上传中,上传完成前不可提交。</div>
2026-05-29 13:30:56 +08:00
<a-modal v-model:open="previewVisible" :footer="null" :mask-closable="false" @cancel="previewVisible = false">
2026-02-26 14:20:35 +08:00
<img alt="预览" style="width: 100%" :src="previewImage" />
</a-modal>
2026-02-25 10:37:16 +08:00
</a-form-item>
<div class="theme-section">
<div class="theme-section__header">
<div>
<div class="theme-section__title">前台主题</div>
<div class="theme-section__desc">用户按该店铺登录后,前台按钮、卡片和渐变会跟随这里的主色调。</div>
</div>
<a-space class="theme-section__actions">
<a-button size="small" @click="openSaveThemeTemplate">保存为模板</a-button>
<a-button size="small" @click="handleResetTheme">恢复默认</a-button>
</a-space>
</div>
<div class="theme-template-panel">
<div class="theme-template-panel__header">
<span>配色模板</span>
<small>选择预设快速应用,也可以把当前 5 个颜色保存成自己的模板。</small>
</div>
<div class="theme-template-list">
<div
v-for="template in themeTemplates"
:key="template.id"
class="theme-template-card"
:class="{
'theme-template-card--active': isThemeTemplateActive(template),
'theme-template-card--custom': template.source === 'custom'
}"
role="button"
tabindex="0"
@click="applyThemeTemplate(template)"
@keydown.enter.prevent="applyThemeTemplate(template)"
@keydown.space.prevent="applyThemeTemplate(template)"
>
<div class="theme-template-card__top">
<strong>{{ template.name }}</strong>
<span>{{ template.source === 'custom' ? '自定义' : '预设' }}</span>
</div>
<div class="theme-template-card__swatches">
<span
v-for="(color, index) in getThemeTemplateSwatches(template)"
:key="`${template.id}-${index}`"
:style="{ background: color }"
></span>
</div>
<a-popconfirm
v-if="template.source === 'custom'"
title="删除这个自定义模板?"
ok-text="删除"
cancel-text="取消"
@confirm="handleDeleteCustomThemeTemplate(template.id)"
>
<button class="theme-template-card__delete" type="button" @click.stop>删除</button>
</a-popconfirm>
</div>
</div>
</div>
<div class="theme-grid">
<a-form-item label="主色" name="themePrimaryColor">
<div class="theme-color-field">
<input v-model="formState.themePrimaryColor" class="theme-color-picker" type="color" />
2026-05-29 13:30:56 +08:00
<a-input v-model:value="formState.themePrimaryColor" placeholder="#E8B4B8" />
</div>
</a-form-item>
<a-form-item label="辅色" name="themeSecondaryColor">
<div class="theme-color-field">
<input v-model="formState.themeSecondaryColor" class="theme-color-picker" type="color" />
2026-05-29 13:30:56 +08:00
<a-input v-model:value="formState.themeSecondaryColor" placeholder="#C5A059" />
</div>
</a-form-item>
2026-05-29 13:30:56 +08:00
<a-form-item label="中性/强调色" name="themeAccentColor">
<div class="theme-color-field">
<input v-model="formState.themeAccentColor" class="theme-color-picker" type="color" />
2026-05-29 13:30:56 +08:00
<a-input v-model:value="formState.themeAccentColor" placeholder="#4A443F" />
</div>
</a-form-item>
<a-form-item label="页面背景" name="themePageBgColor">
<div class="theme-color-field">
<input v-model="formState.themePageBgColor" class="theme-color-picker" type="color" />
2026-05-29 13:30:56 +08:00
<a-input v-model:value="formState.themePageBgColor" placeholder="#FDFBF9" />
</div>
</a-form-item>
<a-form-item label="卡片背景" name="themeCardBgColor">
<div class="theme-color-field">
<input v-model="formState.themeCardBgColor" class="theme-color-picker" type="color" />
<a-input v-model:value="formState.themeCardBgColor" placeholder="#FFFFFF" />
</div>
</a-form-item>
</div>
<a-form-item label="背景图">
<a-upload
v-model:file-list="themeBackgroundFileList"
list-type="picture-card"
:custom-request="handleUploadThemeBackground"
:before-upload="beforeUpload"
@preview="handleThemeBackgroundPreview"
@remove="handleThemeBackgroundRemove"
:max-count="1"
>
<div v-if="themeBackgroundFileList.length < 1">
<plus-outlined />
<div style="margin-top: 8px">上传背景图</div>
</div>
</a-upload>
</a-form-item>
<div class="theme-preview" :style="themePreviewStyle">
<div>
<span class="theme-preview__eyebrow" :style="{ color: themePreview.primaryColor }">Fingertip Designer</span>
<strong>店铺前台预览</strong>
<p>按钮、标签和柔和渐变都会围绕主色延展。</p>
</div>
<span class="theme-preview__button" :style="themePreviewButtonStyle">立即预约</span>
</div>
</div>
<a-modal
v-model:open="themeTemplateSaveVisible"
title="保存配色模板"
ok-text="保存"
cancel-text="取消"
2026-05-29 13:30:56 +08:00
:mask-closable="false"
@ok="handleConfirmSaveThemeTemplate"
@cancel="handleCancelSaveThemeTemplate"
>
<div class="theme-template-save-form">
<label for="theme-template-name">模板名称</label>
<a-input
id="theme-template-name"
v-model:value="themeTemplateName"
:maxlength="20"
show-count
placeholder="例如:春日玫瑰"
@press-enter="handleConfirmSaveThemeTemplate"
/>
</div>
<div class="theme-template-save-preview">
<span
v-for="(color, index) in currentThemeTemplateSwatches"
:key="`current-${index}`"
:style="{ background: color }"
></span>
</div>
</a-modal>
2026-02-25 10:37:16 +08:00
</a-form>
</AdminResponsiveModal>
2026-02-28 14:32:28 +08:00
<!-- 查看店铺详情模态框 -->
<AdminResponsiveModal
2026-02-28 14:32:28 +08:00
v-model:open="viewModalVisible"
title="查看店铺详情"
:desktop-width="700"
2026-02-28 14:32:28 +08:00
@cancel="handleViewModalCancel"
>
<a-form
:model="viewFormState"
:label-col="{ span: 5 }"
:wrapper-col="{ span: 18 }"
>
<a-form-item label="店铺名称">
<a-input v-model:value="viewFormState.shopName" :disabled="true" />
</a-form-item>
<a-form-item label="店铺描述">
<a-textarea
v-model:value="viewFormState.description"
:rows="3"
:disabled="true"
/>
</a-form-item>
<a-form-item label="店铺地址">
<a-input v-model:value="viewFormState.address" :disabled="true" />
</a-form-item>
<a-form-item label="地图位置">
<a-input :value="formatLocation(viewFormState)" :disabled="true" />
</a-form-item>
2026-02-28 14:32:28 +08:00
<a-form-item label="营业时间">
<a-input v-model:value="viewFormState.businessHours" :disabled="true" />
</a-form-item>
<a-form-item label="授权状态">
<a-input :value="viewFormState.authorizationStatusText || '有效'" :disabled="true" />
</a-form-item>
<a-form-item label="授权起始日">
<a-input :value="viewFormState.authorizationStartDate || '长期有效'" :disabled="true" />
</a-form-item>
<a-form-item label="有效期天数">
<a-input :value="viewFormState.authorizationDays ? `${viewFormState.authorizationDays} 天` : '长期有效'" :disabled="true" />
</a-form-item>
<a-form-item label="授权有效期">
<a-input :value="formatAuthorizationExpireTime(viewFormState.authorizationExpireTime)" :disabled="true" />
</a-form-item>
<a-form-item label="前台主题">
<div class="theme-view-swatches">
<span :style="{ background: viewThemePreview.primaryColor }"></span>
<span :style="{ background: viewThemePreview.secondaryColor }"></span>
<span :style="{ background: viewThemePreview.accentColor }"></span>
<span :style="{ background: viewThemePreview.pageBgColor }"></span>
<span :style="{ background: viewThemePreview.cardBgColor }"></span>
</div>
</a-form-item>
<a-form-item label="Banner图片">
<div class="shop-images">
<a-image
v-for="(url, index) in viewBannerUrls"
:key="index"
:width="120"
:height="60"
:src="url"
style="object-fit: cover; border-radius: 4px; margin-right: 8px; margin-bottom: 8px;"
:preview="false"
/>
<span v-if="viewBannerUrls.length === 0" class="no-banner">暂无Banner</span>
</div>
</a-form-item>
2026-02-28 14:32:28 +08:00
<a-form-item label="店铺图片">
<div class="shop-images">
<a-image
v-for="(url, index) in viewImageUrls"
:key="index"
:width="80"
:height="80"
:src="url"
style="object-fit: cover; border-radius: 4px; margin-right: 8px; margin-bottom: 8px;"
:preview="false"
/>
<a-image
v-if="viewImageUrls.length === 0"
:width="80"
:height="80"
:src="DEFAULT_SHOP_IMAGE"
style="object-fit: cover; border-radius: 4px;"
:preview="false"
/>
2026-02-28 14:32:28 +08:00
</div>
</a-form-item>
</a-form>
</AdminResponsiveModal>
<a-modal
v-model:open="mapPickerVisible"
:title="mapPickerTitle"
:width="920"
:footer="null"
2026-05-29 13:30:56 +08:00
:mask-closable="false"
destroy-on-close
class="tencent-map-picker-modal"
@cancel="closeMapLocationPicker"
>
<div class="tencent-map-picker">
<div class="tencent-map-picker__toolbar">
<div>
<strong>搜索并选择店铺位置</strong>
<p>在地图中搜索位置后点击确认,系统会自动回填地址和坐标。</p>
</div>
<a-button :loading="locating" @click="useCurrentLocation">一键获取当前位置</a-button>
</div>
<iframe
v-if="mapPickerUrl"
ref="mapPickerFrame"
class="tencent-map-picker__frame"
:src="mapPickerUrl"
:title="mapPickerTitle"
@load="handleMapPickerFrameLoad"
></iframe>
</div>
</a-modal>
<AdminMobileFab
:visible="isMobile && hasPermission('shop:create') && !modalVisible && !viewModalVisible"
label="新增店铺"
@click="showAddModal"
/>
2026-02-25 10:37:16 +08:00
</div>
</template>
<script setup lang="ts">
/**
* ShopsView page script.
* Call guide: the template binds the reactive state below, and the methods are triggered by button clicks, lifecycle hooks, or router events.
*/
2026-03-26 11:41:38 +08:00
import { computed, ref, reactive, onMounted } from 'vue'
2026-02-25 10:37:16 +08:00
import { message } from 'ant-design-vue'
import type { FormInstance } from 'ant-design-vue'
2026-03-02 10:13:20 +08:00
import { PlusOutlined } from '@ant-design/icons-vue'
2026-03-26 12:04:02 +08:00
import DraftActions from '@/components/DraftActions.vue'
import TableEllipsisText from '@/components/TableEllipsisText.vue'
2026-02-25 10:37:16 +08:00
import { DEFAULT_SHOP_IMAGE } from '@/constants'
2026-05-23 18:44:57 +08:00
/**
* Purpose: Shop supports ShopsView.vue by holding or executing the shop page or API role.
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
*/
import { adminShopApi, adminFileApi, adminSystemParameterConfigApi, type Shop } from '@/api/admin'
2026-05-23 18:44:57 +08:00
/**
* Purpose: ChunkUploadTask supports ShopsView.vue by holding or executing the chunk upload task page or API role.
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-03-26 11:41:38 +08:00
import { createChunkUploadTask, type ChunkUploadTask } from '@/utils/chunk-upload'
2026-03-26 12:04:02 +08:00
import { buildDraftStorageKey, clearDraftRecord, loadDraftRecord, saveDraftRecord } from '@/utils/form-draft'
2026-02-26 17:54:18 +08:00
import { usePermission } from '@/utils/permission'
import { runWithGlobalLoading } from '@/utils/action-loading'
2026-05-29 13:30:56 +08:00
import { notifyShopThemeChanged, resolveShopTheme } from '@/utils/shop-theme'
import { useAdminViewport } from '@/composables/useAdminViewport'
import AdminMobileCardList from '@/components/admin/AdminMobileCardList.vue'
import AdminMobileFab from '@/components/admin/AdminMobileFab.vue'
import AdminResponsiveModal from '@/components/admin/AdminResponsiveModal.vue'
2026-02-26 17:54:18 +08:00
2026-02-26 18:44:47 +08:00
const { hasPermission, loadUserPermissions } = usePermission()
const { isMobile } = useAdminViewport()
2026-02-25 10:37:16 +08:00
2026-05-23 18:44:57 +08:00
/**
* Purpose: ShopThemeTemplateColors supports ShopsView.vue by holding or executing the shop theme template colors page or API role.
* Usage: import, call, read, or update this interface from the owning page/module while preserving the surrounding loading and permission flow.
*/
interface ShopThemeTemplateColors {
themePrimaryColor: string
themeSecondaryColor: string
themeAccentColor: string
themePageBgColor: string
themeCardBgColor: string
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: ShopThemeTemplate supports ShopsView.vue by holding or executing the shop theme template page or API role.
* Usage: import, call, read, or update this interface from the owning page/module while preserving the surrounding loading and permission flow.
*/
interface ShopThemeTemplate extends ShopThemeTemplateColors {
id: string
name: string
source: 'preset' | 'custom'
createdAt?: number
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: CUSTOM_THEME_TEMPLATE_STORAGE_KEY supports ShopsView.vue by holding or executing the custom theme template storage key page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const CUSTOM_THEME_TEMPLATE_STORAGE_KEY = 'yuminail:admin:shop-theme-templates'
2026-05-23 18:44:57 +08:00
/**
* Purpose: CUSTOM_THEME_TEMPLATE_LIMIT supports ShopsView.vue by holding or executing the custom theme template limit page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const CUSTOM_THEME_TEMPLATE_LIMIT = 20
const PRESET_THEME_TEMPLATES: ShopThemeTemplate[] = [
2026-05-29 13:30:56 +08:00
{
id: 'preset-luminous-elegance',
name: 'Luminous Elegance',
source: 'preset',
themePrimaryColor: '#E8B4B8',
themeSecondaryColor: '#C5A059',
themeAccentColor: '#4A443F',
themePageBgColor: '#FDFBF9',
themeCardBgColor: '#FFFFFF'
},
{
id: 'preset-soft-nude',
name: '柔雾裸粉',
source: 'preset',
themePrimaryColor: '#C6597D',
themeSecondaryColor: '#E9B7C7',
themeAccentColor: '#9F4967',
themePageBgColor: '#FFF7F9',
themeCardBgColor: '#FFFFFF'
},
{
id: 'preset-rose-milk-tea',
name: '玫瑰奶茶',
source: 'preset',
themePrimaryColor: '#B96D79',
themeSecondaryColor: '#E6C0B7',
themeAccentColor: '#8D4D58',
themePageBgColor: '#FFF8F5',
themeCardBgColor: '#FFFFFF'
},
{
id: 'preset-peach-velvet',
name: '蜜桃绒光',
source: 'preset',
themePrimaryColor: '#D87986',
themeSecondaryColor: '#F0C6B4',
themeAccentColor: '#B85C6D',
themePageBgColor: '#FFF6F2',
themeCardBgColor: '#FFFFFF'
},
{
id: 'preset-misty-berry',
name: '雾莓豆沙',
source: 'preset',
themePrimaryColor: '#A85F76',
themeSecondaryColor: '#D7A9B8',
themeAccentColor: '#7E4258',
themePageBgColor: '#FBF4F7',
themeCardBgColor: '#FFFFFF'
},
{
id: 'preset-champagne-coral',
name: '香槟珊瑚',
source: 'preset',
themePrimaryColor: '#C97865',
themeSecondaryColor: '#EBC7AA',
themeAccentColor: '#A4574D',
themePageBgColor: '#FFF8F1',
themeCardBgColor: '#FFFFFF'
},
{
id: 'preset-magnolia-cream',
name: '玉兰米白',
source: 'preset',
themePrimaryColor: '#A46E79',
themeSecondaryColor: '#E7D4CC',
themeAccentColor: '#7C555F',
themePageBgColor: '#FBF7F2',
themeCardBgColor: '#FFFFFF'
},
{
id: 'preset-smoky-mauve',
name: '烟粉灰调',
source: 'preset',
themePrimaryColor: '#9B6A78',
themeSecondaryColor: '#D8BCC4',
themeAccentColor: '#72505B',
themePageBgColor: '#F8F4F5',
themeCardBgColor: '#FFFFFF'
},
{
id: 'preset-berry-brown',
name: '莓果红棕',
source: 'preset',
themePrimaryColor: '#9E5366',
themeSecondaryColor: '#D9A0AD',
themeAccentColor: '#6F3948',
themePageBgColor: '#FFF5F7',
themeCardBgColor: '#FFFFFF'
},
{
id: 'preset-cream-rose',
name: '奶油玫瑰',
source: 'preset',
themePrimaryColor: '#D28A9C',
themeSecondaryColor: '#F0CFD6',
themeAccentColor: '#A85A71',
themePageBgColor: '#FFF9FA',
themeCardBgColor: '#FFFFFF'
},
{
id: 'preset-sakura-salon',
name: '静谧樱花',
source: 'preset',
themePrimaryColor: '#BF7892',
themeSecondaryColor: '#E8C6D2',
themeAccentColor: '#8E5369',
themePageBgColor: '#FFF7FA',
themeCardBgColor: '#FFFFFF'
}
]
/** loading is a reactive state variable used by the template and event handlers. */
2026-02-25 10:37:16 +08:00
const loading = ref(false)
/** searchText is a reactive state variable used by the template and event handlers. */
2026-02-25 10:37:16 +08:00
const searchText = ref('')
2026-05-23 18:44:57 +08:00
/**
* Purpose: shopList supports ShopsView.vue by holding or executing the shop list page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-02-25 14:44:50 +08:00
const shopList = ref<Shop[]>([])
/** modalVisible is a reactive state variable used by the template and event handlers. */
2026-02-25 10:37:16 +08:00
const modalVisible = ref(false)
/** viewModalVisible is a reactive state variable used by the template and event handlers. */
2026-02-28 14:32:28 +08:00
const viewModalVisible = ref(false)
/** modalLoading is a reactive state variable used by the template and event handlers. */
2026-02-25 10:37:16 +08:00
const modalLoading = ref(false)
/** isEdit is a reactive state variable used by the template and event handlers. */
2026-02-25 10:37:16 +08:00
const isEdit = ref(false)
2026-05-23 18:44:57 +08:00
/**
* Purpose: mapPickerVisible supports ShopsView.vue by holding or executing the map picker visible page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const mapPickerVisible = ref(false)
2026-05-23 18:44:57 +08:00
/**
* Purpose: mapPickerKey supports ShopsView.vue by holding or executing the map picker key page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const mapPickerKey = ref('')
2026-05-23 18:44:57 +08:00
/**
* Purpose: mapPickerUrl supports ShopsView.vue by holding or executing the map picker url page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const mapPickerUrl = ref('')
2026-05-23 18:44:57 +08:00
/**
* Purpose: mapPickerProvider supports ShopsView.vue by holding or executing the map picker provider page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const mapPickerProvider = ref<'TENCENT' | 'AMAP'>('TENCENT')
2026-05-23 18:44:57 +08:00
/**
* Purpose: locating supports ShopsView.vue by holding or executing the locating page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const locating = ref(false)
2026-05-23 18:44:57 +08:00
/**
* Purpose: formRef supports ShopsView.vue by holding or executing the form ref page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-02-25 10:37:16 +08:00
const formRef = ref<FormInstance>()
2026-05-23 18:44:57 +08:00
/**
* Purpose: currentShop supports ShopsView.vue by holding or executing the current shop page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-02-25 14:44:50 +08:00
const currentShop = ref<Shop | null>(null)
/** isAdmin is a reactive state variable used by the template and event handlers. */
2026-02-26 18:44:47 +08:00
const isAdmin = ref(false)
2026-02-25 10:37:16 +08:00
// Banner图片相关
const bannerFileList = ref<any[]>([])
2026-05-23 18:44:57 +08:00
/**
* Purpose: uploadedBannerIds supports ShopsView.vue by holding or executing the uploaded banner ids page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const uploadedBannerIds = ref<string[]>([])
/** bannerPreviewVisible is a reactive state variable used by the template and event handlers. */
const bannerPreviewVisible = ref(false)
/** bannerPreviewImage is a reactive state variable used by the template and event handlers. */
const bannerPreviewImage = ref('')
// 店铺图片相关
2026-02-26 14:20:35 +08:00
const imageFileList = ref<any[]>([])
2026-05-23 18:44:57 +08:00
/**
* Purpose: uploadedFileIds supports ShopsView.vue by holding or executing the uploaded file ids page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-02-26 14:20:35 +08:00
const uploadedFileIds = ref<string[]>([])
2026-05-23 18:44:57 +08:00
/**
* Purpose: themeBackgroundFileList supports ShopsView.vue by holding or executing the theme background file list page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const themeBackgroundFileList = ref<any[]>([])
2026-05-23 18:44:57 +08:00
/**
* Purpose: uploadedThemeBackgroundId supports ShopsView.vue by holding or executing the uploaded theme background id page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const uploadedThemeBackgroundId = ref('')
2026-05-23 18:44:57 +08:00
/**
* Purpose: imageIdCache supports ShopsView.vue by holding or executing the image id cache page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-02-26 14:20:35 +08:00
const imageIdCache = ref<Record<string, string>>({})
2026-05-23 18:44:57 +08:00
/**
* Purpose: shopImageUrls supports ShopsView.vue by holding or executing the shop image urls page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-03-27 14:55:41 +08:00
const shopImageUrls = ref<Record<string, string[]>>({})
2026-05-23 18:44:57 +08:00
/**
* Purpose: shopBannerUrls supports ShopsView.vue by holding or executing the shop banner urls page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-03-27 14:55:41 +08:00
const shopBannerUrls = ref<Record<string, string[]>>({})
2026-05-23 18:44:57 +08:00
/**
* Purpose: viewImageUrls supports ShopsView.vue by holding or executing the view image urls page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-02-28 14:32:28 +08:00
const viewImageUrls = ref<string[]>([])
2026-05-23 18:44:57 +08:00
/**
* Purpose: viewBannerUrls supports ShopsView.vue by holding or executing the view banner urls page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const viewBannerUrls = ref<string[]>([])
/** previewVisible is a reactive state variable used by the template and event handlers. */
2026-02-26 14:20:35 +08:00
const previewVisible = ref(false)
/** previewImage is a reactive state variable used by the template and event handlers. */
2026-02-26 14:20:35 +08:00
const previewImage = ref('')
/** businessStartTime is a reactive state variable used by the template and event handlers. */
2026-03-21 13:16:39 +08:00
const businessStartTime = ref('')
/** businessEndTime is a reactive state variable used by the template and event handlers. */
2026-03-21 13:16:39 +08:00
const businessEndTime = ref('')
2026-05-23 18:44:57 +08:00
/**
* Purpose: uploadTaskMap supports ShopsView.vue by holding or executing the upload task map page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-03-26 11:41:38 +08:00
const uploadTaskMap = new Map<string, ChunkUploadTask<any>>()
/** activeUploadCount is a reactive state variable used by the template and event handlers. */
2026-03-26 11:41:38 +08:00
const activeUploadCount = ref(0)
/** isUploadPending is a reactive state variable used by the template and event handlers. */
2026-03-26 11:41:38 +08:00
const isUploadPending = computed(() => activeUploadCount.value > 0)
2026-05-23 18:44:57 +08:00
/**
* Purpose: draftSavedAt supports ShopsView.vue by holding or executing the draft saved at page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-03-26 12:04:02 +08:00
const draftSavedAt = ref<number | null>(null)
2026-05-23 18:44:57 +08:00
/**
* Purpose: customThemeTemplates supports ShopsView.vue by holding or executing the custom theme templates page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const customThemeTemplates = ref<ShopThemeTemplate[]>([])
2026-05-23 18:44:57 +08:00
/**
* Purpose: themeTemplateSaveVisible supports ShopsView.vue by holding or executing the theme template save visible page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const themeTemplateSaveVisible = ref(false)
2026-05-23 18:44:57 +08:00
/**
* Purpose: themeTemplateName supports ShopsView.vue by holding or executing the theme template name page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const themeTemplateName = ref('')
2026-02-26 14:20:35 +08:00
2026-02-28 14:32:28 +08:00
// 查看店铺相关状态
const viewFormState = reactive({
shopName: '',
description: '',
address: '',
mapProvider: 'TENCENT',
longitude: '',
latitude: '',
2026-02-28 14:32:28 +08:00
businessHours: '',
status: 1,
authorizationStartDate: '',
authorizationDays: undefined as number | undefined,
authorizationExpireTime: '',
authorizationStatusText: '',
coverImageFileId: '',
imageFileIds: '',
themePrimaryColor: '',
themeSecondaryColor: '',
themeAccentColor: '',
themePageBgColor: '',
themeCardBgColor: '',
themeBackgroundImageFileId: ''
2026-02-28 14:32:28 +08:00
})
2026-05-23 18:44:57 +08:00
/**
* Purpose: pagination supports ShopsView.vue by holding or executing the pagination page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-02-25 10:37:16 +08:00
const pagination = reactive({
current: 1,
pageSize: 10,
total: 0,
showSizeChanger: true,
showQuickJumper: true,
showTotal: (total: number) => `共 ${total} 条`
})
2026-05-23 18:44:57 +08:00
/**
* Purpose: formState supports ShopsView.vue by holding or executing the form state page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-02-25 10:37:16 +08:00
const formState = reactive({
2026-02-25 14:44:50 +08:00
shopName: '',
2026-02-25 10:37:16 +08:00
description: '',
address: '',
mapProvider: 'TENCENT',
longitude: '',
latitude: '',
2026-02-25 10:37:16 +08:00
businessHours: '',
status: 1,
authorizationStartDate: '',
authorizationDays: undefined as number | undefined,
authorizationExpireTime: '',
coverImageFileId: '',
imageFileIds: '',
themePrimaryColor: '',
themeSecondaryColor: '',
themeAccentColor: '',
themePageBgColor: '',
themeCardBgColor: '',
themeBackgroundImageFileId: ''
2026-02-25 10:37:16 +08:00
})
2026-05-23 18:44:57 +08:00
/**
* Purpose: selectedLocationText supports ShopsView.vue by holding or executing the selected location text page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const selectedLocationText = computed(() => {
if (formState.address) return formState.address
if (formState.longitude && formState.latitude) return '已选择地图位置'
return '暂未选择地图位置'
})
2026-05-23 18:44:57 +08:00
/**
* Purpose: selectedCoordinateText supports ShopsView.vue by holding or executing the selected coordinate text page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const selectedCoordinateText = computed(() => {
if (!formState.longitude || !formState.latitude) return '点击“地图选点”搜索店铺名称或地址'
return '已选择地图位置,可重新选点'
})
2026-05-23 18:44:57 +08:00
/**
* Purpose: mapPickerTitle supports ShopsView.vue by holding or executing the map picker title page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const mapPickerTitle = computed(() => mapPickerProvider.value === 'AMAP' ? '高德地图选点' : '腾讯地图选点')
2026-05-23 18:44:57 +08:00
/**
* Purpose: computedAuthorizationExpireTime supports ShopsView.vue by holding or executing the computed authorization expire time page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const computedAuthorizationExpireTime = computed(() => {
if (!formState.authorizationStartDate || !formState.authorizationDays || formState.authorizationDays <= 0) {
return formState.authorizationExpireTime || ''
}
const start = new Date(`${formState.authorizationStartDate}T00:00:00`)
start.setDate(start.getDate() + Number(formState.authorizationDays) - 1)
const yyyy = start.getFullYear()
const mm = String(start.getMonth() + 1).padStart(2, '0')
const dd = String(start.getDate()).padStart(2, '0')
return `${yyyy}-${mm}-${dd} 23:59:59`
})
2026-05-23 18:44:57 +08:00
/**
* Purpose: computedAuthorizationExpireTimeText supports ShopsView.vue by holding or executing the computed authorization expire time text page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const computedAuthorizationExpireTimeText = computed(() => formatAuthorizationExpireTime(computedAuthorizationExpireTime.value))
2026-05-23 18:44:57 +08:00
/**
* Purpose: themePreview supports ShopsView.vue by holding or executing the theme preview page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const themePreview = computed(() => resolveShopTheme(formState))
2026-05-23 18:44:57 +08:00
/**
* Purpose: viewThemePreview supports ShopsView.vue by holding or executing the view theme preview page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const viewThemePreview = computed(() => resolveShopTheme(viewFormState))
2026-05-23 18:44:57 +08:00
/**
* Purpose: themePreviewStyle supports ShopsView.vue by holding or executing the theme preview style page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const themePreviewStyle = computed(() => ({
color: themePreview.value.textPrimary,
borderColor: themePreview.value.borderColor,
background: themePreview.value.softGradient
}))
2026-05-23 18:44:57 +08:00
/**
* Purpose: themePreviewButtonStyle supports ShopsView.vue by holding or executing the theme preview button style page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const themePreviewButtonStyle = computed(() => ({
color: '#ffffff',
background: themePreview.value.gradient,
boxShadow: themePreview.value.cssVars['--theme-button-shadow']
}))
2026-05-23 18:44:57 +08:00
/**
* Purpose: themeTemplates supports ShopsView.vue by holding or executing the theme templates page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const themeTemplates = computed(() => [...PRESET_THEME_TEMPLATES, ...customThemeTemplates.value])
2026-05-23 18:44:57 +08:00
/**
* Purpose: currentThemeTemplateColors supports ShopsView.vue by holding or executing the current theme template colors page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const currentThemeTemplateColors = computed(() => buildThemeTemplateColors(formState))
2026-05-23 18:44:57 +08:00
/**
* Purpose: currentThemeTemplateSwatches supports ShopsView.vue by holding or executing the current theme template swatches page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const currentThemeTemplateSwatches = computed(() => getThemeTemplateSwatches(currentThemeTemplateColors.value))
2026-05-23 18:44:57 +08:00
/**
* Purpose: normalizeTemplateColor supports ShopsView.vue by holding or executing the normalize template color page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const normalizeTemplateColor = (value?: string) => {
const normalized = String(value || '').trim().toUpperCase()
return /^#[0-9A-F]{6}$/.test(normalized) ? normalized : ''
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: buildThemeTemplateColors supports ShopsView.vue by holding or executing the build theme template colors page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const buildThemeTemplateColors = (source: Record<string, any>): ShopThemeTemplateColors => {
const resolvedTheme = resolveShopTheme(source)
return {
themePrimaryColor: resolvedTheme.primaryColor,
themeSecondaryColor: resolvedTheme.secondaryColor,
themeAccentColor: resolvedTheme.accentColor,
themePageBgColor: resolvedTheme.pageBgColor,
themeCardBgColor: resolvedTheme.cardBgColor
}
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: getThemeTemplateSwatches supports ShopsView.vue by holding or executing the get theme template swatches page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const getThemeTemplateSwatches = (template: ShopThemeTemplateColors) => [
template.themePrimaryColor,
template.themeSecondaryColor,
template.themeAccentColor,
template.themePageBgColor,
template.themeCardBgColor
]
2026-05-23 18:44:57 +08:00
/**
* Purpose: normalizeThemeTemplate supports ShopsView.vue by holding or executing the normalize theme template page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const normalizeThemeTemplate = (value: any): ShopThemeTemplate | null => {
if (!value || typeof value !== 'object') {
return null
}
const name = String(value.name || '').trim()
const colors = {
themePrimaryColor: normalizeTemplateColor(value.themePrimaryColor),
themeSecondaryColor: normalizeTemplateColor(value.themeSecondaryColor),
themeAccentColor: normalizeTemplateColor(value.themeAccentColor),
themePageBgColor: normalizeTemplateColor(value.themePageBgColor),
themeCardBgColor: normalizeTemplateColor(value.themeCardBgColor)
}
if (!name || Object.values(colors).some(color => !color)) {
return null
}
return {
id: String(value.id || `custom-${Date.now()}`),
name,
source: 'custom',
createdAt: Number(value.createdAt) || Date.now(),
...colors
}
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: persistCustomThemeTemplates supports ShopsView.vue by holding or executing the persist custom theme templates page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const persistCustomThemeTemplates = () => {
if (typeof window === 'undefined') {
return
}
window.localStorage.setItem(getThemeTemplateStorageKey(), JSON.stringify(customThemeTemplates.value))
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: loadCustomThemeTemplates supports ShopsView.vue by holding or executing the load custom theme templates page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const loadCustomThemeTemplates = () => {
if (typeof window === 'undefined') {
return
}
try {
const rawValue = window.localStorage.getItem(getThemeTemplateStorageKey())
const parsedValue = rawValue ? JSON.parse(rawValue) : []
customThemeTemplates.value = Array.isArray(parsedValue)
? parsedValue.map(normalizeThemeTemplate).filter((item): item is ShopThemeTemplate => Boolean(item))
: []
} catch {
customThemeTemplates.value = []
}
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: isThemeTemplateActive supports ShopsView.vue by holding or executing the is theme template active page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const isThemeTemplateActive = (template: ShopThemeTemplateColors) => {
const currentColors = currentThemeTemplateColors.value
return getThemeTemplateSwatches(template).every((color, index) => color === getThemeTemplateSwatches(currentColors)[index])
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: themeColorValidator supports ShopsView.vue by holding or executing the theme color validator page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const themeColorValidator = async (_rule: any, value?: string) => {
if (!value) {
return Promise.resolve()
}
if (/^#[0-9a-fA-F]{6}$/.test(value.trim())) {
return Promise.resolve()
}
return Promise.reject('请输入 #RRGGBB 格式颜色')
}
2026-03-02 10:13:20 +08:00
const formRules: any = {
2026-02-25 14:44:50 +08:00
shopName: [{ required: true, message: '请输入店铺名称', trigger: 'blur' }],
2026-02-25 10:37:16 +08:00
description: [{ required: true, message: '请输入店铺描述', trigger: 'blur' }],
address: [{ required: true, message: '请输入店铺地址', trigger: 'blur' }],
2026-03-21 13:16:39 +08:00
businessHours: [{
validator: async () => {
if (!businessStartTime.value || !businessEndTime.value) {
return Promise.reject('请选择营业开始和结束时间')
}
if (businessStartTime.value >= businessEndTime.value) {
return Promise.reject('营业结束时间必须晚于开始时间')
}
return Promise.resolve()
},
trigger: 'change'
}],
authorizationDays: [{
validator: async () => {
if (formState.authorizationStartDate && (!formState.authorizationDays || formState.authorizationDays <= 0)) {
return Promise.reject('请输入授权有效期天数')
}
return Promise.resolve()
},
trigger: 'change'
}],
themePrimaryColor: [{ validator: themeColorValidator, trigger: 'blur' }],
themeSecondaryColor: [{ validator: themeColorValidator, trigger: 'blur' }],
themeAccentColor: [{ validator: themeColorValidator, trigger: 'blur' }],
themePageBgColor: [{ validator: themeColorValidator, trigger: 'blur' }],
themeCardBgColor: [{ validator: themeColorValidator, trigger: 'blur' }]
2026-02-25 10:37:16 +08:00
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: columns supports ShopsView.vue by holding or executing the columns page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-02-25 10:37:16 +08:00
const columns = [
2026-02-26 14:20:35 +08:00
{ title: '图片', key: 'image', width: 150 },
{ title: 'Banner', key: 'banner', width: 200 },
2026-02-25 14:44:50 +08:00
{ title: '店铺名称', dataIndex: 'shopName', key: 'shopName' },
{ title: '店铺描述', dataIndex: 'description', key: 'description' },
2026-02-25 10:37:16 +08:00
{ title: '店铺地址', dataIndex: 'address', key: 'address' },
{ title: '营业时间', dataIndex: 'businessHours', key: 'businessHours' },
{ title: '状态', key: 'status', width: 120 },
{ title: '授权', key: 'authorization', width: 180 },
2026-02-25 10:37:16 +08:00
{ title: '创建时间', dataIndex: 'createTime', key: 'createTime' },
{ title: '操作', key: 'actions', width: 150, fixed: 'right' as const }
]
/** getCurrentUserInfo is a local helper used by this page script. */
const getCurrentUserInfo = () => {
try {
const userInfoStr = localStorage.getItem('adminUserInfo')
if (userInfoStr) {
2026-02-26 18:44:47 +08:00
const userInfo = JSON.parse(userInfoStr)
// 判断用户是否为管理员(类型为4)
isAdmin.value = userInfo.type === 4
return userInfo
}
} catch (error) {
console.error('获取当前用户信息失败', error)
}
return null
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: getThemeTemplateStorageKey supports ShopsView.vue by holding or executing the get theme template storage key page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const getThemeTemplateStorageKey = () => {
const currentUser = getCurrentUserInfo()
const userKey = currentUser?.id ?? currentUser?.userId ?? currentUser?.account ?? currentUser?.username ?? 'default'
return `${CUSTOM_THEME_TEMPLATE_STORAGE_KEY}:${userKey}`
}
/** loadImageUrls is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
2026-02-26 14:20:35 +08:00
const loadImageUrls = async (shops: Shop[]) => {
for (const shop of shops) {
// 加载店铺图片
2026-02-26 14:20:35 +08:00
if (shop.imageFileIds) {
const ids = shop.imageFileIds.split(',')
const urls: string[] = []
for (const id of ids) {
if (id) {
try {
// 检查缓存
if (!imageIdCache.value[id]) {
2026-03-27 14:55:41 +08:00
const response = await adminFileApi.getSignedUrl(id.trim()) as any
2026-03-02 10:13:20 +08:00
imageIdCache.value[id] = response
2026-02-26 14:20:35 +08:00
}
2026-03-10 23:23:15 +08:00
urls.push(imageIdCache.value[id]!)
2026-02-26 14:20:35 +08:00
} catch (error) {
console.error('获取签名链接失败:', error)
urls.push(DEFAULT_SHOP_IMAGE)
}
}
}
2026-03-10 23:23:15 +08:00
if (shop.id !== undefined) {
2026-03-27 14:55:41 +08:00
shopImageUrls.value[String(shop.id)] = urls
2026-03-10 23:23:15 +08:00
}
2026-02-26 14:20:35 +08:00
} else {
2026-03-10 23:23:15 +08:00
if (shop.id !== undefined) {
2026-03-27 14:55:41 +08:00
shopImageUrls.value[String(shop.id)] = []
2026-03-10 23:23:15 +08:00
}
}
// 加载Banner图片
if (shop.coverImageFileId) {
const ids = shop.coverImageFileId.split(',')
const urls: string[] = []
for (const id of ids) {
if (id) {
try {
// 检查缓存
if (!imageIdCache.value[id]) {
2026-03-27 14:55:41 +08:00
const response = await adminFileApi.getSignedUrl(id.trim()) as any
imageIdCache.value[id] = response
}
2026-03-10 23:23:15 +08:00
urls.push(imageIdCache.value[id]!)
} catch (error) {
console.error('获取签名链接失败:', error)
urls.push(DEFAULT_SHOP_IMAGE)
}
}
}
2026-03-10 23:23:15 +08:00
if (shop.id !== undefined) {
2026-03-27 14:55:41 +08:00
shopBannerUrls.value[String(shop.id)] = urls
2026-03-10 23:23:15 +08:00
}
} else {
2026-03-10 23:23:15 +08:00
if (shop.id !== undefined) {
2026-03-27 14:55:41 +08:00
shopBannerUrls.value[String(shop.id)] = []
2026-03-10 23:23:15 +08:00
}
2026-02-26 14:20:35 +08:00
}
}
}
/** getShopImages is a local helper used by this page script. */
2026-03-02 10:13:20 +08:00
const getShopImages = (shop: Shop | Record<string, any>): string[] => {
const shopId = 'id' in shop ? shop.id : (shop as any).id
2026-03-10 23:23:15 +08:00
if (shopId !== undefined) {
2026-03-27 14:55:41 +08:00
return shopImageUrls.value[String(shopId)] || []
2026-03-10 23:23:15 +08:00
}
return []
}
/** getShopBannerImages is a local helper used by this page script. */
const getShopBannerImages = (shop: Shop | Record<string, any>): string[] => {
const shopId = 'id' in shop ? shop.id : (shop as any).id
2026-03-10 23:23:15 +08:00
if (shopId !== undefined) {
2026-03-27 14:55:41 +08:00
return shopBannerUrls.value[String(shopId)] || []
2026-03-10 23:23:15 +08:00
}
return []
2026-02-26 14:20:35 +08:00
}
/** formatAuthorizationExpireTime is a local helper used by this page script. */
const formatAuthorizationExpireTime = (value?: string) => {
if (!value) {
return '长期有效'
}
return value.replace('T', ' ').slice(0, 16)
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: formatLocation supports ShopsView.vue by holding or executing the format location page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const formatLocation = (shop?: Partial<Shop> | Record<string, any>) => {
const locationName = shop?.address || shop?.shopName || ''
if (!locationName) return '未设置地图位置'
return locationName || '未设置地图位置'
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: buildTencentLocationPickerUrl supports ShopsView.vue by holding or executing the build tencent location picker url page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const buildTencentLocationPickerUrl = (options: { latitude?: string | number; longitude?: string | number } = {}) => {
const params = new URLSearchParams({
search: '1',
type: '1',
key: mapPickerKey.value,
referer: 'yuminail',
keyword: formState.address || formState.shopName || ''
})
const latitude = options.latitude || formState.latitude
const longitude = options.longitude || formState.longitude
if (latitude && longitude) {
params.set('coord', `${latitude},${longitude}`)
}
return `https://apis.map.qq.com/tools/locpicker?${params.toString()}`
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: buildAmapLocationPickerUrl supports ShopsView.vue by holding or executing the build amap location picker url page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const buildAmapLocationPickerUrl = (options: { latitude?: string | number; longitude?: string | number } = {}) => {
const params = new URLSearchParams({
key: mapPickerKey.value,
keywords: formState.address || formState.shopName || '',
zoom: '16'
})
const latitude = options.latitude || formState.latitude
const longitude = options.longitude || formState.longitude
if (latitude && longitude) {
params.set('center', `${longitude},${latitude}`)
}
return `https://m.amap.com/picker/?${params.toString()}`
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: buildMapLocationPickerUrl supports ShopsView.vue by holding or executing the build map location picker url page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const buildMapLocationPickerUrl = (options: { latitude?: string | number; longitude?: string | number } = {}) => {
return mapPickerProvider.value === 'AMAP'
? buildAmapLocationPickerUrl(options)
: buildTencentLocationPickerUrl(options)
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: closeTencentLocationPicker supports ShopsView.vue by holding or executing the close tencent location picker page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const closeTencentLocationPicker = () => {
mapPickerVisible.value = false
window.removeEventListener('message', handleMapLocationMessage)
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: closeMapLocationPicker supports ShopsView.vue by holding or executing the close map location picker page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const closeMapLocationPicker = closeTencentLocationPicker
2026-05-23 18:44:57 +08:00
/**
* Purpose: applyTencentLocation supports ShopsView.vue by holding or executing the apply tencent location page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const applyTencentLocation = (data: any) => {
const location = data.loclatlng || data.latlng || data.location
if (!location) return
formState.latitude = String(location.lat || location.latitude || '')
formState.longitude = String(location.lng || location.longitude || '')
formState.mapProvider = mapPickerProvider.value
const placeName = data.poiname || data.name || data.title || ''
const placeAddress = data.poiaddress || data.addr || data.address || ''
if (placeName && placeAddress) {
formState.address = `${placeName} - ${placeAddress}`
} else if (placeAddress || placeName) {
formState.address = placeAddress || placeName
}
if (placeName && !formState.shopName) {
formState.shopName = placeName
}
message.success(`已选择:${placeName || placeAddress || '地图位置'}`)
closeTencentLocationPicker()
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: applyAmapLocation supports ShopsView.vue by holding or executing the apply amap location page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const applyAmapLocation = (data: any) => {
const rawLocation = data.location || data.lnglat || data.position
let longitude = ''
let latitude = ''
if (typeof rawLocation === 'string') {
const [lng, lat] = rawLocation.split(',').map(item => item.trim())
longitude = lng || ''
latitude = lat || ''
} else if (rawLocation && typeof rawLocation === 'object') {
longitude = String(rawLocation.lng || rawLocation.longitude || rawLocation.lon || rawLocation.x || '')
latitude = String(rawLocation.lat || rawLocation.latitude || rawLocation.y || '')
}
if (!longitude || !latitude) return
formState.latitude = latitude
formState.longitude = longitude
formState.mapProvider = 'AMAP'
const placeName = data.name || data.poiname || data.title || ''
const placeAddress = data.address || data.poiaddress || data.addr || ''
if (placeName && placeAddress) {
formState.address = `${placeName} - ${placeAddress}`
} else if (placeAddress || placeName) {
formState.address = placeAddress || placeName
}
if (placeName && !formState.shopName) {
formState.shopName = placeName
}
message.success(`已选择:${placeName || placeAddress || '地图位置'}`)
closeTencentLocationPicker()
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: handleMapLocationMessage supports ShopsView.vue by holding or executing the handle map location message page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const handleMapLocationMessage = (event: MessageEvent) => {
const data = event.data || {}
if (!data || typeof data !== 'object') return
if (data.module === 'locationPicker' || data.module === 'locationPicker_v2') {
applyTencentLocation(data)
return
}
if (mapPickerProvider.value === 'AMAP') {
applyAmapLocation(data)
}
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: openMapLocationPicker supports ShopsView.vue by holding or executing the open map location picker page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const openMapLocationPicker = async () => {
const response = await adminSystemParameterConfigApi.getMapConfig()
const provider = response?.provider === 'AMAP' ? 'AMAP' : 'TENCENT'
const key = provider === 'AMAP' ? (response?.amapWebKey || '') : (response?.tencentWebKey || '')
if (!key) {
message.warning(provider === 'AMAP'
? '请先在参数管理中配置高德 Web Key'
: '请先在参数管理中配置腾讯 Web Key')
return
}
mapPickerProvider.value = provider
mapPickerKey.value = key
mapPickerUrl.value = buildMapLocationPickerUrl()
mapPickerVisible.value = true
window.removeEventListener('message', handleMapLocationMessage)
window.addEventListener('message', handleMapLocationMessage)
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: handleMapPickerFrameLoad supports ShopsView.vue by holding or executing the handle map picker frame load page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const handleMapPickerFrameLoad = () => {
// 高德/腾讯选点页均通过 postMessage 回传结果,此处保留钩子便于后续接入加载态。
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: useCurrentLocation supports ShopsView.vue by holding or executing the use current location page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const useCurrentLocation = () => {
if (!navigator.geolocation) {
message.warning('当前浏览器不支持定位')
return
}
if (!mapPickerKey.value) {
message.warning('请先打开地图选点')
return
}
locating.value = true
navigator.geolocation.getCurrentPosition(
position => {
const accuracy = Number(position.coords.accuracy)
if (Number.isFinite(accuracy) && accuracy > 1000) {
locating.value = false
message.warning(`当前位置误差约 ${Math.round(accuracy)} 米,定位不够准确,请直接在地图中搜索或点选店铺位置`)
return
}
const latitude = position.coords.latitude.toFixed(6)
const longitude = position.coords.longitude.toFixed(6)
mapPickerUrl.value = buildMapLocationPickerUrl({ latitude, longitude })
locating.value = false
const accuracyText = Number.isFinite(accuracy) ? `,当前位置约有 ${Math.round(accuracy)} 米误差` : ''
message.info(`已定位到当前位置附近${accuracyText},请在地图中确认后保存`)
},
() => {
locating.value = false
message.error('获取当前位置失败,请检查浏览器定位权限')
},
{ enableHighAccuracy: true, timeout: 10000, maximumAge: 60000 }
)
}
/** fetchShopList is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
2026-02-25 10:37:16 +08:00
const fetchShopList = async () => {
loading.value = true
try {
const currentUser = getCurrentUserInfo()
const params: any = {
2026-02-25 10:37:16 +08:00
page: pagination.current,
size: pagination.pageSize,
keyword: searchText.value
}
if (currentUser && currentUser.type !== 4 && currentUser.shopId) {
params.shopId = currentUser.shopId
}
2026-03-02 10:13:20 +08:00
const response = await adminShopApi.listShops(params)
const res = typeof response === 'object' && 'list' in response ? response : (response as any).data
2026-02-25 10:37:16 +08:00
shopList.value = res.list || []
pagination.total = res.total || 0
2026-02-26 14:20:35 +08:00
// 预加载所有图片签名链接
await loadImageUrls(res.list || [])
2026-02-25 10:37:16 +08:00
} catch (error) {
message.error('获取店铺列表失败')
} finally {
loading.value = false
}
}
/** handleSearch is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const handleSearch = async () => {
2026-02-25 10:37:16 +08:00
pagination.current = 1
await runWithGlobalLoading(() => fetchShopList())
2026-02-25 10:37:16 +08:00
}
/** handleTableChange is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const handleTableChange = async (pag: any) => {
2026-02-25 10:37:16 +08:00
pagination.current = pag.current
pagination.pageSize = pag.pageSize
await runWithGlobalLoading(() => fetchShopList())
2026-02-25 10:37:16 +08:00
}
/** beforeUpload is a local helper used by this page script. */
2026-02-26 14:20:35 +08:00
const beforeUpload = (file: File) => {
const isImage = file.type.startsWith('image/')
if (!isImage) {
message.error('只能上传图片文件!')
}
const isLt2M = file.size / 1024 / 1024 < 2
if (!isLt2M) {
message.error('图片大小不能超过 2MB!')
}
return isImage && isLt2M
}
2026-03-27 15:04:58 +08:00
// Banner 与门店环境图分开维护上传任务,便于表单回显和删除时分别同步 fileId 列表。
/** handleUploadBanner is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const handleUploadBanner = async (options: any) => {
2026-03-26 11:41:38 +08:00
const { file, onSuccess, onError, onProgress } = options
const taskKey = `banner:${String(file.uid)}`
const task = createChunkUploadTask({
file: file as File,
scene: 'admin-shop-banner',
api: {
initUpload: adminFileApi.initChunkUpload,
uploadChunk: adminFileApi.uploadChunk,
completeUpload: adminFileApi.completeChunkUpload,
cancelUpload: adminFileApi.cancelChunkUpload
},
onProgress: (percent) => {
onProgress?.({ percent })
}
})
uploadTaskMap.set(taskKey, task)
activeUploadCount.value += 1
try {
2026-03-26 11:41:38 +08:00
const { response } = await task.promise
const fileId = String((response as any).id)
syncUploadedBannerIds([...uploadedBannerIds.value, fileId])
onSuccess?.({ id: fileId, fileId })
message.success('Banner上传成功')
} catch (error) {
2026-03-26 11:41:38 +08:00
const errorMessage = (error as Error)?.message || 'Banner上传失败'
if (errorMessage !== '上传已取消' && errorMessage !== 'canceled') {
console.error('Banner上传失败:', error)
message.error(errorMessage)
onError?.(error)
}
} finally {
uploadTaskMap.delete(taskKey)
activeUploadCount.value = Math.max(0, activeUploadCount.value - 1)
}
}
/** handleBannerPreview is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const handleBannerPreview = async (file: any) => {
try {
2026-03-26 11:41:38 +08:00
const cachedPreviewUrl = getPreviewUrlFromFile(file)
if (cachedPreviewUrl) {
bannerPreviewImage.value = cachedPreviewUrl
bannerPreviewVisible.value = true
return
}
2026-03-26 11:41:38 +08:00
const fileId = resolveUploadedFileId(file)
if (!fileId) {
throw new Error('未找到图片文件标识')
}
if (!imageIdCache.value[fileId]) {
2026-03-27 14:55:41 +08:00
const response = await adminFileApi.getSignedUrl(fileId) as any
2026-03-26 11:41:38 +08:00
imageIdCache.value[fileId] = response
}
bannerPreviewImage.value = imageIdCache.value[fileId] || ''
bannerPreviewVisible.value = true
} catch (error) {
console.error('获取预览链接失败:', error)
2026-03-26 11:41:38 +08:00
message.error((error as Error)?.message || '获取预览链接失败')
}
}
/** handleBannerRemove is a local helper used by this page script. */
const handleBannerRemove = (file: any) => {
2026-03-26 11:41:38 +08:00
const task = uploadTaskMap.get(`banner:${String(file.uid)}`)
if (task) {
task.cancel()
return true
}
2026-03-26 11:41:38 +08:00
const fileId = resolveUploadedFileId(file)
if (fileId) {
syncUploadedBannerIds(uploadedBannerIds.value.filter(id => id !== fileId))
}
return true
}
2026-03-27 15:04:58 +08:00
// 店铺环境图与 Banner 走同一套分片上传协议,但写入不同业务字段。
/** handleUploadImage is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
2026-02-26 14:20:35 +08:00
const handleUploadImage = async (options: any) => {
2026-03-26 11:41:38 +08:00
const { file, onSuccess, onError, onProgress } = options
const taskKey = `image:${String(file.uid)}`
const task = createChunkUploadTask({
file: file as File,
scene: 'admin-shop-image',
api: {
initUpload: adminFileApi.initChunkUpload,
uploadChunk: adminFileApi.uploadChunk,
completeUpload: adminFileApi.completeChunkUpload,
cancelUpload: adminFileApi.cancelChunkUpload
},
onProgress: (percent) => {
onProgress?.({ percent })
}
})
uploadTaskMap.set(taskKey, task)
activeUploadCount.value += 1
2026-02-26 14:20:35 +08:00
try {
2026-03-26 11:41:38 +08:00
const { response } = await task.promise
const fileId = String((response as any).id)
syncUploadedFileIds([...uploadedFileIds.value, fileId])
onSuccess?.({ id: fileId, fileId })
2026-02-26 14:20:35 +08:00
message.success('图片上传成功')
} catch (error) {
2026-03-26 11:41:38 +08:00
const errorMessage = (error as Error)?.message || '图片上传失败'
if (errorMessage !== '上传已取消' && errorMessage !== 'canceled') {
console.error('图片上传失败:', error)
message.error(errorMessage)
onError?.(error)
}
} finally {
uploadTaskMap.delete(taskKey)
activeUploadCount.value = Math.max(0, activeUploadCount.value - 1)
2026-02-26 14:20:35 +08:00
}
}
2026-03-27 15:04:58 +08:00
// 编辑态下 Upload 里的文件可能只剩 fileId,所以预览时需要兼容本地 URL 与远端签名地址两种来源。
/** handlePreview is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
2026-02-26 14:20:35 +08:00
const handlePreview = async (file: any) => {
try {
2026-03-26 11:41:38 +08:00
const cachedPreviewUrl = getPreviewUrlFromFile(file)
if (cachedPreviewUrl) {
previewImage.value = cachedPreviewUrl
previewVisible.value = true
return
2026-02-26 14:20:35 +08:00
}
2026-03-26 11:41:38 +08:00
const fileId = resolveUploadedFileId(file)
if (!fileId) {
throw new Error('未找到图片文件标识')
}
if (!imageIdCache.value[fileId]) {
2026-03-27 14:55:41 +08:00
const response = await adminFileApi.getSignedUrl(fileId) as any
2026-03-26 11:41:38 +08:00
imageIdCache.value[fileId] = response
}
previewImage.value = imageIdCache.value[fileId] || ''
2026-02-26 14:20:35 +08:00
previewVisible.value = true
} catch (error) {
console.error('获取预览链接失败:', error)
2026-03-26 11:41:38 +08:00
message.error((error as Error)?.message || '获取预览链接失败')
2026-02-26 14:20:35 +08:00
}
}
/** handleRemove is a local helper used by this page script. */
2026-02-26 14:20:35 +08:00
const handleRemove = (file: any) => {
2026-03-26 11:41:38 +08:00
const task = uploadTaskMap.get(`image:${String(file.uid)}`)
if (task) {
task.cancel()
return true
2026-02-26 14:20:35 +08:00
}
2026-03-26 11:41:38 +08:00
const fileId = resolveUploadedFileId(file)
if (fileId) {
syncUploadedFileIds(uploadedFileIds.value.filter(id => id !== fileId))
}
return true
2026-02-26 14:20:35 +08:00
}
/** handleUploadThemeBackground is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const handleUploadThemeBackground = async (options: any) => {
const { file, onSuccess, onError, onProgress } = options
const taskKey = `theme-bg:${String(file.uid)}`
const task = createChunkUploadTask({
file: file as File,
scene: 'admin-shop-theme-background',
api: {
initUpload: adminFileApi.initChunkUpload,
uploadChunk: adminFileApi.uploadChunk,
completeUpload: adminFileApi.completeChunkUpload,
cancelUpload: adminFileApi.cancelChunkUpload
},
onProgress: (percent) => {
onProgress?.({ percent })
}
})
uploadTaskMap.set(taskKey, task)
activeUploadCount.value += 1
try {
const { response } = await task.promise
const fileId = String((response as any).id)
syncUploadedThemeBackgroundId(fileId)
onSuccess?.({ id: fileId, fileId })
message.success('背景图上传成功')
} catch (error) {
const errorMessage = (error as Error)?.message || '背景图上传失败'
if (errorMessage !== '上传已取消' && errorMessage !== 'canceled') {
console.error('背景图上传失败:', error)
message.error(errorMessage)
onError?.(error)
}
} finally {
uploadTaskMap.delete(taskKey)
activeUploadCount.value = Math.max(0, activeUploadCount.value - 1)
}
}
/** handleThemeBackgroundPreview is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const handleThemeBackgroundPreview = async (file: any) => {
try {
const cachedPreviewUrl = getPreviewUrlFromFile(file)
if (cachedPreviewUrl) {
bannerPreviewImage.value = cachedPreviewUrl
bannerPreviewVisible.value = true
return
}
const fileId = resolveUploadedFileId(file)
if (!fileId) {
throw new Error('未找到背景图文件标识')
}
if (!imageIdCache.value[fileId]) {
const response = await adminFileApi.getSignedUrl(fileId) as any
imageIdCache.value[fileId] = response
}
bannerPreviewImage.value = imageIdCache.value[fileId] || ''
bannerPreviewVisible.value = true
} catch (error) {
console.error('获取背景图预览链接失败:', error)
message.error((error as Error)?.message || '获取背景图预览链接失败')
}
}
/** handleThemeBackgroundRemove is a local helper used by this page script. */
const handleThemeBackgroundRemove = (file: any) => {
const task = uploadTaskMap.get(`theme-bg:${String(file.uid)}`)
if (task) {
task.cancel()
return true
}
const fileId = resolveUploadedFileId(file)
if (fileId) {
syncUploadedThemeBackgroundId('')
}
return true
}
/** syncBusinessHoursValue is a local helper used by this page script. */
2026-03-21 13:16:39 +08:00
const syncBusinessHoursValue = () => {
formState.businessHours = businessStartTime.value && businessEndTime.value
? `${businessStartTime.value}-${businessEndTime.value}`
: ''
}
/** setBusinessHoursValue is a local helper used by this page script. */
2026-03-21 13:16:39 +08:00
const setBusinessHoursValue = (value?: string) => {
const matched = (value || '').match(/(\d{2}:\d{2})\s*-\s*(\d{2}:\d{2})/)
businessStartTime.value = matched?.[1] || ''
businessEndTime.value = matched?.[2] || ''
syncBusinessHoursValue()
}
/** handleBusinessHoursChange is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
2026-03-21 13:16:39 +08:00
const handleBusinessHoursChange = async () => {
syncBusinessHoursValue()
await formRef.value?.validateFields?.(['businessHours']).catch(() => undefined)
}
/** showAddModal is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
2026-03-26 12:04:02 +08:00
const showAddModal = async () => {
2026-02-25 10:37:16 +08:00
isEdit.value = false
2026-03-26 12:04:02 +08:00
currentShop.value = null
2026-02-25 10:37:16 +08:00
Object.assign(formState, {
2026-02-25 14:44:50 +08:00
shopName: '',
2026-02-25 10:37:16 +08:00
description: '',
address: '',
mapProvider: 'TENCENT',
longitude: '',
latitude: '',
2026-02-25 10:37:16 +08:00
businessHours: '',
status: 1,
authorizationStartDate: '',
authorizationDays: undefined,
authorizationExpireTime: '',
coverImageFileId: '',
imageFileIds: '',
themePrimaryColor: '',
themeSecondaryColor: '',
themeAccentColor: '',
themePageBgColor: '',
themeCardBgColor: '',
themeBackgroundImageFileId: ''
2026-02-25 10:37:16 +08:00
})
2026-03-21 13:16:39 +08:00
setBusinessHoursValue('')
bannerFileList.value = []
2026-03-26 11:41:38 +08:00
syncUploadedBannerIds([])
2026-02-26 14:20:35 +08:00
imageFileList.value = []
2026-03-26 11:41:38 +08:00
syncUploadedFileIds([])
themeBackgroundFileList.value = []
syncUploadedThemeBackgroundId('')
2026-03-26 12:04:02 +08:00
await restoreDraft()
2026-02-25 10:37:16 +08:00
modalVisible.value = true
}
/** showEditModal is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
2026-03-02 10:13:20 +08:00
const showEditModal = async (record: Shop | Record<string, any>) => {
2026-02-25 10:37:16 +08:00
isEdit.value = true
2026-03-02 10:13:20 +08:00
currentShop.value = record as Shop
2026-02-25 10:37:16 +08:00
Object.assign(formState, {
2026-03-02 10:13:20 +08:00
shopName: 'shopName' in record ? record.shopName : (record as any).shopName,
description: 'description' in record ? record.description : (record as any).description,
address: 'address' in record ? record.address : (record as any).address,
mapProvider: 'TENCENT',
longitude: 'longitude' in record ? record.longitude : (record as any).longitude,
latitude: 'latitude' in record ? record.latitude : (record as any).latitude,
2026-03-02 10:13:20 +08:00
businessHours: 'businessHours' in record ? record.businessHours : (record as any).businessHours,
status: 'status' in record ? (record.status ?? 1) : ((record as any).status ?? 1),
authorizationStartDate: 'authorizationStartDate' in record ? record.authorizationStartDate : (record as any).authorizationStartDate,
authorizationDays: 'authorizationDays' in record ? record.authorizationDays : (record as any).authorizationDays,
authorizationExpireTime: 'authorizationExpireTime' in record ? record.authorizationExpireTime : (record as any).authorizationExpireTime,
coverImageFileId: 'coverImageFileId' in record ? record.coverImageFileId : (record as any).coverImageFileId,
imageFileIds: 'imageFileIds' in record ? record.imageFileIds : (record as any).imageFileIds,
themePrimaryColor: 'themePrimaryColor' in record ? record.themePrimaryColor : (record as any).themePrimaryColor,
themeSecondaryColor: 'themeSecondaryColor' in record ? record.themeSecondaryColor : (record as any).themeSecondaryColor,
themeAccentColor: 'themeAccentColor' in record ? record.themeAccentColor : (record as any).themeAccentColor,
themePageBgColor: 'themePageBgColor' in record ? record.themePageBgColor : (record as any).themePageBgColor,
themeCardBgColor: 'themeCardBgColor' in record ? record.themeCardBgColor : (record as any).themeCardBgColor,
themeBackgroundImageFileId: 'themeBackgroundImageFileId' in record ? record.themeBackgroundImageFileId : (record as any).themeBackgroundImageFileId
2026-02-25 10:37:16 +08:00
})
2026-03-21 13:16:39 +08:00
setBusinessHoursValue(formState.businessHours)
2026-02-26 14:20:35 +08:00
// 加载Banner图片
const coverImageFileId = 'coverImageFileId' in record ? record.coverImageFileId : (record as any).coverImageFileId
if (coverImageFileId) {
2026-03-26 11:41:38 +08:00
const ids = coverImageFileId.split(',').filter((id: string) => id)
syncUploadedBannerIds(ids)
2026-03-26 12:04:02 +08:00
bannerFileList.value = await buildShopUploadFileList(ids, 'Banner')
} else {
bannerFileList.value = []
2026-03-26 11:41:38 +08:00
syncUploadedBannerIds([])
}
// 加载店铺图片
2026-03-02 10:13:20 +08:00
const imageFileIds = 'imageFileIds' in record ? record.imageFileIds : (record as any).imageFileIds
if (imageFileIds) {
2026-03-26 11:41:38 +08:00
const ids = imageFileIds.split(',').filter((id: string) => id)
syncUploadedFileIds(ids)
2026-03-26 12:04:02 +08:00
imageFileList.value = await buildShopUploadFileList(ids, '图片')
2026-02-26 14:20:35 +08:00
} else {
imageFileList.value = []
2026-03-26 11:41:38 +08:00
syncUploadedFileIds([])
2026-02-26 14:20:35 +08:00
}
const themeBackgroundImageFileId = 'themeBackgroundImageFileId' in record
? record.themeBackgroundImageFileId
: (record as any).themeBackgroundImageFileId
if (themeBackgroundImageFileId) {
const id = String(themeBackgroundImageFileId)
syncUploadedThemeBackgroundId(id)
themeBackgroundFileList.value = await buildShopUploadFileList([id], '背景图')
} else {
themeBackgroundFileList.value = []
syncUploadedThemeBackgroundId('')
}
2026-02-26 14:20:35 +08:00
2026-03-26 12:04:02 +08:00
await restoreDraft()
2026-02-25 10:37:16 +08:00
modalVisible.value = true
}
/** showViewModal is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
2026-03-02 10:13:20 +08:00
const showViewModal = async (record: Shop | Record<string, any>) => {
2026-02-28 14:32:28 +08:00
Object.assign(viewFormState, {
2026-03-02 10:13:20 +08:00
shopName: 'shopName' in record ? record.shopName : (record as any).shopName,
description: 'description' in record ? record.description : (record as any).description,
address: 'address' in record ? record.address : (record as any).address,
mapProvider: 'TENCENT',
longitude: 'longitude' in record ? record.longitude : (record as any).longitude,
latitude: 'latitude' in record ? record.latitude : (record as any).latitude,
2026-03-02 10:13:20 +08:00
businessHours: 'businessHours' in record ? record.businessHours : (record as any).businessHours,
status: 'status' in record ? (record.status ?? 1) : ((record as any).status ?? 1),
authorizationStartDate: 'authorizationStartDate' in record ? record.authorizationStartDate : (record as any).authorizationStartDate,
authorizationDays: 'authorizationDays' in record ? record.authorizationDays : (record as any).authorizationDays,
authorizationExpireTime: 'authorizationExpireTime' in record ? record.authorizationExpireTime : (record as any).authorizationExpireTime,
authorizationStatusText: 'authorizationStatusText' in record ? record.authorizationStatusText : (record as any).authorizationStatusText,
coverImageFileId: 'coverImageFileId' in record ? record.coverImageFileId : (record as any).coverImageFileId,
imageFileIds: 'imageFileIds' in record ? record.imageFileIds : (record as any).imageFileIds,
themePrimaryColor: 'themePrimaryColor' in record ? record.themePrimaryColor : (record as any).themePrimaryColor,
themeSecondaryColor: 'themeSecondaryColor' in record ? record.themeSecondaryColor : (record as any).themeSecondaryColor,
themeAccentColor: 'themeAccentColor' in record ? record.themeAccentColor : (record as any).themeAccentColor,
themePageBgColor: 'themePageBgColor' in record ? record.themePageBgColor : (record as any).themePageBgColor,
themeCardBgColor: 'themeCardBgColor' in record ? record.themeCardBgColor : (record as any).themeCardBgColor,
themeBackgroundImageFileId: 'themeBackgroundImageFileId' in record ? record.themeBackgroundImageFileId : (record as any).themeBackgroundImageFileId
2026-02-28 14:32:28 +08:00
})
// 加载Banner图片URL
const coverImageFileId = 'coverImageFileId' in record ? record.coverImageFileId : (record as any).coverImageFileId
if (coverImageFileId) {
2026-03-26 11:41:38 +08:00
const ids = coverImageFileId.split(',').filter((id: string) => id)
const urls: string[] = []
for (const id of ids) {
try {
// 检查缓存
if (!imageIdCache.value[id]) {
2026-03-27 14:55:41 +08:00
const response = await adminFileApi.getSignedUrl(id.trim()) as any
imageIdCache.value[id] = response
}
2026-03-10 23:23:15 +08:00
urls.push(imageIdCache.value[id]!)
} catch (error) {
console.error('获取签名链接失败:', error)
urls.push(DEFAULT_SHOP_IMAGE)
}
}
viewBannerUrls.value = urls
} else {
viewBannerUrls.value = []
}
// 加载店铺图片URL
2026-03-02 10:13:20 +08:00
const imageFileIds = 'imageFileIds' in record ? record.imageFileIds : (record as any).imageFileIds
if (imageFileIds) {
2026-03-26 11:41:38 +08:00
const ids = imageFileIds.split(',').filter((id: string) => id)
2026-02-28 14:32:28 +08:00
const urls: string[] = []
for (const id of ids) {
try {
// 检查缓存
if (!imageIdCache.value[id]) {
2026-03-27 14:55:41 +08:00
const response = await adminFileApi.getSignedUrl(id.trim()) as any
2026-03-02 10:13:20 +08:00
imageIdCache.value[id] = response
2026-02-28 14:32:28 +08:00
}
2026-03-10 23:23:15 +08:00
urls.push(imageIdCache.value[id]!)
2026-02-28 14:32:28 +08:00
} catch (error) {
console.error('获取签名链接失败:', error)
urls.push(DEFAULT_SHOP_IMAGE)
}
}
viewImageUrls.value = urls
} else {
viewImageUrls.value = []
2026-02-28 14:32:28 +08:00
}
viewModalVisible.value = true
}
/** handleViewModalCancel is a local helper used by this page script. */
2026-02-28 14:32:28 +08:00
const handleViewModalCancel = () => {
viewModalVisible.value = false
viewImageUrls.value = []
viewBannerUrls.value = []
2026-02-28 14:32:28 +08:00
}
/** cancelAllPendingUploads is a local helper used by this page script. */
2026-03-26 11:41:38 +08:00
const cancelAllPendingUploads = () => {
uploadTaskMap.forEach(task => task.cancel())
}
/** getDraftKey is a local helper used by this page script. */
2026-03-26 12:04:02 +08:00
const getDraftKey = () => buildDraftStorageKey('admin-shops', isEdit.value ? 'edit' : 'create', currentShop.value?.id ?? 'new')
/** buildDraftPayload is a local helper used by this page script. */
2026-03-26 12:04:02 +08:00
const buildDraftPayload = () => ({
formState: {
shopName: formState.shopName,
description: formState.description,
address: formState.address,
mapProvider: 'TENCENT',
longitude: formState.longitude,
latitude: formState.latitude,
2026-03-26 12:04:02 +08:00
businessHours: formState.businessHours,
status: formState.status,
authorizationStartDate: formState.authorizationStartDate,
authorizationDays: formState.authorizationDays,
authorizationExpireTime: formState.authorizationExpireTime,
2026-03-26 12:04:02 +08:00
coverImageFileId: formState.coverImageFileId,
imageFileIds: formState.imageFileIds,
themePrimaryColor: formState.themePrimaryColor,
themeSecondaryColor: formState.themeSecondaryColor,
themeAccentColor: formState.themeAccentColor,
themePageBgColor: formState.themePageBgColor,
themeCardBgColor: formState.themeCardBgColor,
themeBackgroundImageFileId: formState.themeBackgroundImageFileId
2026-03-26 12:04:02 +08:00
},
businessStartTime: businessStartTime.value,
businessEndTime: businessEndTime.value,
uploadedBannerIds: [...uploadedBannerIds.value],
uploadedFileIds: [...uploadedFileIds.value],
uploadedThemeBackgroundId: uploadedThemeBackgroundId.value
2026-03-26 12:04:02 +08:00
})
/** buildShopUploadFileList is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
2026-03-26 12:04:02 +08:00
const buildShopUploadFileList = async (ids: string[], fileNamePrefix: string) => {
const fileList = []
for (const [index, id] of ids.entries()) {
try {
if (!imageIdCache.value[id]) {
2026-03-27 14:55:41 +08:00
const response = await adminFileApi.getSignedUrl(id.trim()) as any
2026-03-26 12:04:02 +08:00
imageIdCache.value[id] = response
}
fileList.push({
uid: id,
fileId: id,
name: `${fileNamePrefix}${index + 1}`,
status: 'done',
url: imageIdCache.value[id]
})
} catch (error) {
console.error('获取签名链接失败:', error)
fileList.push({
uid: id,
fileId: id,
name: `${fileNamePrefix}${index + 1}`,
status: 'done',
url: ''
})
}
}
return fileList
}
/** restoreDraft is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
2026-03-26 12:04:02 +08:00
const restoreDraft = async () => {
const draft = loadDraftRecord<ReturnType<typeof buildDraftPayload>>(getDraftKey())
if (!draft) {
draftSavedAt.value = null
return
}
Object.assign(formState, draft.payload.formState)
businessStartTime.value = draft.payload.businessStartTime || ''
businessEndTime.value = draft.payload.businessEndTime || ''
syncUploadedBannerIds(draft.payload.uploadedBannerIds || [])
syncUploadedFileIds(draft.payload.uploadedFileIds || [])
syncUploadedThemeBackgroundId(draft.payload.uploadedThemeBackgroundId || '')
2026-03-26 12:04:02 +08:00
bannerFileList.value = await buildShopUploadFileList(uploadedBannerIds.value, 'Banner')
imageFileList.value = await buildShopUploadFileList(uploadedFileIds.value, '图片')
themeBackgroundFileList.value = uploadedThemeBackgroundId.value
? await buildShopUploadFileList([uploadedThemeBackgroundId.value], '背景图')
: []
2026-03-26 12:04:02 +08:00
draftSavedAt.value = draft.savedAt
message.success('已恢复暂存内容')
}
/** handleSaveDraft is a local helper used by this page script. */
2026-03-26 12:04:02 +08:00
const handleSaveDraft = () => {
if (isUploadPending.value) {
message.warning('图片上传完成后才能暂存')
return
}
const draft = saveDraftRecord(getDraftKey(), buildDraftPayload())
draftSavedAt.value = draft.savedAt
message.success('已暂存到本地')
}
/** handleClearDraft is a local helper used by this page script. */
2026-03-26 12:04:02 +08:00
const handleClearDraft = (showMessage = true) => {
clearDraftRecord(getDraftKey())
draftSavedAt.value = null
if (showMessage) {
message.success('已清除暂存')
}
}
/** syncUploadedBannerIds is a local helper used by this page script. */
2026-03-26 11:41:38 +08:00
const syncUploadedBannerIds = (fileIds: string[]) => {
uploadedBannerIds.value = Array.from(new Set(fileIds.filter(id => Boolean(id))))
formState.coverImageFileId = uploadedBannerIds.value.join(',')
}
/** syncUploadedFileIds is a local helper used by this page script. */
2026-03-26 11:41:38 +08:00
const syncUploadedFileIds = (fileIds: string[]) => {
uploadedFileIds.value = Array.from(new Set(fileIds.filter(id => Boolean(id))))
formState.imageFileIds = uploadedFileIds.value.join(',')
}
/** syncUploadedThemeBackgroundId is a local helper used by this page script. */
const syncUploadedThemeBackgroundId = (fileId: string) => {
uploadedThemeBackgroundId.value = fileId || ''
formState.themeBackgroundImageFileId = uploadedThemeBackgroundId.value
if (!uploadedThemeBackgroundId.value) {
themeBackgroundFileList.value = []
}
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: handleResetTheme supports ShopsView.vue by holding or executing the handle reset theme page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const handleResetTheme = () => {
Object.assign(formState, {
themePrimaryColor: '',
themeSecondaryColor: '',
themeAccentColor: '',
themePageBgColor: '',
themeCardBgColor: '',
themeBackgroundImageFileId: ''
})
themeBackgroundFileList.value = []
syncUploadedThemeBackgroundId('')
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: applyThemeTemplate supports ShopsView.vue by holding or executing the apply theme template page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const applyThemeTemplate = (template: ShopThemeTemplate) => {
Object.assign(formState, {
themePrimaryColor: template.themePrimaryColor,
themeSecondaryColor: template.themeSecondaryColor,
themeAccentColor: template.themeAccentColor,
themePageBgColor: template.themePageBgColor,
themeCardBgColor: template.themeCardBgColor
})
message.success(`已应用「${template.name}」配色`)
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: openSaveThemeTemplate supports ShopsView.vue by holding or executing the open save theme template page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const openSaveThemeTemplate = () => {
themeTemplateName.value = formState.shopName ? `${formState.shopName}主题` : '我的配色模板'
themeTemplateSaveVisible.value = true
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: handleCancelSaveThemeTemplate supports ShopsView.vue by holding or executing the handle cancel save theme template page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const handleCancelSaveThemeTemplate = () => {
themeTemplateSaveVisible.value = false
themeTemplateName.value = ''
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: handleConfirmSaveThemeTemplate supports ShopsView.vue by holding or executing the handle confirm save theme template page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const handleConfirmSaveThemeTemplate = () => {
const name = themeTemplateName.value.trim()
if (!name) {
message.warning('请输入模板名称')
return
}
if (PRESET_THEME_TEMPLATES.some(template => template.name === name)) {
message.warning('这个名称已被预设模板占用,请换一个')
return
}
const existedIndex = customThemeTemplates.value.findIndex(template => template.name === name)
const template: ShopThemeTemplate = {
id: existedIndex >= 0 ? customThemeTemplates.value[existedIndex]!.id : `custom-${Date.now()}`,
name,
source: 'custom',
createdAt: Date.now(),
...currentThemeTemplateColors.value
}
customThemeTemplates.value = existedIndex >= 0
? customThemeTemplates.value.map((item, index) => index === existedIndex ? template : item)
: [template, ...customThemeTemplates.value].slice(0, CUSTOM_THEME_TEMPLATE_LIMIT)
persistCustomThemeTemplates()
themeTemplateSaveVisible.value = false
themeTemplateName.value = ''
message.success(existedIndex >= 0 ? '已更新同名配色模板' : '已保存配色模板')
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: handleDeleteCustomThemeTemplate supports ShopsView.vue by holding or executing the handle delete custom theme template page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const handleDeleteCustomThemeTemplate = (id: string) => {
customThemeTemplates.value = customThemeTemplates.value.filter(template => template.id !== id)
persistCustomThemeTemplates()
message.success('已删除配色模板')
}
/** getUploadResponse is a local helper used by this page script. */
2026-03-26 11:41:38 +08:00
const getUploadResponse = (file: any) => {
if (!file || typeof file !== 'object') {
return null
}
return file.response || null
}
/** resolveUploadedFileId is a local helper used by this page script. */
2026-03-26 11:41:38 +08:00
const resolveUploadedFileId = (file: any) => {
const response = getUploadResponse(file)
const responseId = response?.id ?? response?.data?.id ?? file?.fileId
if (responseId !== undefined && responseId !== null && responseId !== '') {
return String(responseId)
}
const fileUid = String(file?.uid || '')
if (/^\d+$/.test(fileUid)) {
return fileUid
}
const fileUrl = String(file?.url || '')
if (/^\d+$/.test(fileUrl)) {
return fileUrl
}
return ''
}
/** getPreviewUrlFromFile is a local helper used by this page script. */
2026-03-26 11:41:38 +08:00
const getPreviewUrlFromFile = (file: any) => {
const fileUrl = typeof file?.url === 'string' ? file.url : ''
if (fileUrl && !/^\d+$/.test(fileUrl)) {
return fileUrl
}
const thumbUrl = typeof file?.thumbUrl === 'string' ? file.thumbUrl : ''
if (thumbUrl) {
return thumbUrl
}
return ''
}
/** handleModalOk is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
2026-02-25 10:37:16 +08:00
const handleModalOk = async () => {
try {
2026-03-26 11:41:38 +08:00
if (isUploadPending.value) {
message.warning('图片上传完成前不可提交')
return
}
2026-03-21 13:16:39 +08:00
syncBusinessHoursValue()
2026-02-25 10:37:16 +08:00
await formRef.value?.validate()
modalLoading.value = true
await runWithGlobalLoading(async () => {
if (isEdit.value && currentShop.value) {
await adminShopApi.updateShop(currentShop.value.id, {
...formState,
authorizationExpireTime: computedAuthorizationExpireTime.value
})
2026-05-29 13:30:56 +08:00
notifyShopThemeChanged()
message.success('更新成功')
} else {
await adminShopApi.createShop({
...formState,
authorizationExpireTime: computedAuthorizationExpireTime.value
})
message.success('创建成功')
}
handleClearDraft(false)
modalVisible.value = false
await fetchShopList()
})
2026-02-25 10:37:16 +08:00
} catch (error) {
console.error(error)
} finally {
modalLoading.value = false
}
}
/** handleModalCancel is a local helper used by this page script. */
2026-02-25 10:37:16 +08:00
const handleModalCancel = () => {
2026-03-26 11:41:38 +08:00
cancelAllPendingUploads()
2026-02-25 10:37:16 +08:00
modalVisible.value = false
formRef.value?.resetFields()
2026-03-21 13:16:39 +08:00
setBusinessHoursValue('')
bannerFileList.value = []
2026-03-26 11:41:38 +08:00
syncUploadedBannerIds([])
2026-02-26 14:20:35 +08:00
imageFileList.value = []
2026-03-26 11:41:38 +08:00
syncUploadedFileIds([])
themeBackgroundFileList.value = []
syncUploadedThemeBackgroundId('')
2026-02-25 10:37:16 +08:00
}
/** handleStatusChange is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const handleStatusChange = async (record: Shop | Record<string, any>, enabled: boolean) => {
try {
await runWithGlobalLoading(async () => {
const shopId = 'id' in record ? record.id : (record as any).id
await adminShopApi.updateShopStatus(shopId, enabled ? 1 : 0)
;(record as any).status = enabled ? 1 : 0
message.success(`店铺已${enabled ? '启用' : '停用'}`)
})
} catch (error) {
message.error('店铺状态更新失败')
}
}
2026-02-26 18:44:47 +08:00
onMounted(async () => {
loadCustomThemeTemplates()
2026-02-26 18:44:47 +08:00
await loadUserPermissions()
2026-02-25 10:37:16 +08:00
fetchShopList()
})
</script>
<style scoped>
.shops {
padding: 0;
}
2026-02-26 14:20:35 +08:00
.shop-images {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 4px;
}
.map-picker-card {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 10px 12px;
2026-05-29 13:30:56 +08:00
border: 1px solid var(--theme-border);
border-radius: 8px;
2026-05-29 13:30:56 +08:00
background: var(--theme-card-bg);
}
.map-picker-main {
min-width: 0;
flex: 1;
}
.map-picker-title {
2026-05-29 13:30:56 +08:00
color: var(--text-primary);
font-weight: 600;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.map-picker-subtitle {
margin-top: 4px;
2026-05-29 13:30:56 +08:00
color: var(--text-secondary);
font-size: 12px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.map-picker-tip {
margin-top: 8px;
2026-05-29 13:30:56 +08:00
color: var(--text-secondary);
font-size: 12px;
line-height: 1.6;
}
.tencent-map-picker {
display: grid;
gap: 12px;
}
.tencent-map-picker__toolbar {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
}
.tencent-map-picker__toolbar p {
margin: 4px 0 0;
2026-05-29 13:30:56 +08:00
color: var(--text-secondary);
font-size: 13px;
}
.tencent-map-picker__frame {
width: 100%;
height: 520px;
border: 0;
border-radius: 8px;
2026-05-29 13:30:56 +08:00
background: var(--theme-primary-soft);
}
.shop-banner {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 4px;
2026-02-26 14:20:35 +08:00
}
.no-banner {
2026-05-29 13:30:56 +08:00
color: var(--text-secondary);
font-size: 12px;
}
.upload-tip {
2026-05-29 13:30:56 +08:00
color: var(--text-secondary);
font-size: 12px;
margin-bottom: 8px;
2026-02-26 14:20:35 +08:00
}
2026-03-21 13:16:39 +08:00
2026-03-26 11:41:38 +08:00
.upload-pending-tip {
color: #fa8c16;
font-size: 12px;
margin-top: 8px;
}
2026-03-21 13:16:39 +08:00
.business-hours-picker {
display: flex;
align-items: center;
gap: 12px;
width: 100%;
}
.business-hours-separator {
2026-05-29 13:30:56 +08:00
color: var(--text-secondary);
2026-03-21 13:16:39 +08:00
flex: 0 0 auto;
}
.theme-section {
margin: 8px 0 18px;
padding: 16px 18px;
2026-05-29 13:30:56 +08:00
border: 1px solid var(--theme-border);
border-radius: 8px;
2026-05-29 13:30:56 +08:00
background: var(--theme-primary-soft);
}
.theme-section__header {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 16px;
margin-bottom: 16px;
}
.theme-section__title {
2026-05-29 13:30:56 +08:00
color: var(--text-primary);
font-weight: 700;
}
.theme-section__desc {
margin-top: 4px;
2026-05-29 13:30:56 +08:00
color: var(--text-secondary);
font-size: 12px;
line-height: 1.6;
}
.theme-section__actions {
flex: 0 0 auto;
}
.theme-template-panel {
margin-bottom: 16px;
padding: 12px;
2026-05-29 13:30:56 +08:00
border: 1px solid var(--theme-border);
border-radius: 8px;
2026-05-29 13:30:56 +08:00
background: var(--theme-card-bg);
}
.theme-template-panel__header {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 12px;
}
.theme-template-panel__header span {
2026-05-29 13:30:56 +08:00
color: var(--text-primary);
font-weight: 700;
}
.theme-template-panel__header small {
2026-05-29 13:30:56 +08:00
color: var(--text-secondary);
line-height: 1.5;
}
.theme-template-list {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
gap: 10px;
}
.theme-template-card {
position: relative;
min-height: 92px;
padding: 12px;
2026-05-29 13:30:56 +08:00
border: 1px solid var(--theme-border);
border-radius: 8px;
2026-05-29 13:30:56 +08:00
background: var(--theme-card-bg);
cursor: pointer;
transition: border-color .2s ease, box-shadow .2s ease, transform .2s ease;
}
.theme-template-card:hover,
.theme-template-card:focus {
2026-05-29 13:30:56 +08:00
border-color: var(--theme-primary);
box-shadow: var(--theme-button-shadow);
outline: none;
transform: translateY(-1px);
}
.theme-template-card--active {
2026-05-29 13:30:56 +08:00
border-color: var(--theme-primary);
background: var(--theme-primary-soft);
box-shadow: var(--theme-focus-shadow);
}
.theme-template-card--custom {
padding-right: 54px;
}
.theme-template-card__top {
display: grid;
gap: 4px;
}
.theme-template-card__top strong {
2026-05-29 13:30:56 +08:00
color: var(--text-primary);
font-size: 13px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.theme-template-card__top span {
2026-05-29 13:30:56 +08:00
color: var(--text-secondary);
font-size: 12px;
}
.theme-template-card__swatches {
display: flex;
align-items: center;
gap: 5px;
margin-top: 16px;
}
.theme-template-card__swatches span,
.theme-template-save-preview span {
width: 18px;
height: 18px;
2026-05-29 13:30:56 +08:00
border: 2px solid var(--theme-card-bg);
border-radius: 999px;
2026-05-29 13:30:56 +08:00
box-shadow: 0 0 0 1px var(--theme-border);
}
.theme-template-card__delete {
position: absolute;
top: 9px;
right: 9px;
height: 24px;
padding: 0 8px;
2026-05-29 13:30:56 +08:00
border: 1px solid var(--theme-border);
border-radius: 8px;
2026-05-29 13:30:56 +08:00
color: var(--theme-accent);
font-size: 12px;
2026-05-29 13:30:56 +08:00
background: var(--theme-primary-soft);
cursor: pointer;
}
.theme-template-card__delete:hover,
.theme-template-card__delete:focus {
2026-05-29 13:30:56 +08:00
border-color: var(--theme-primary);
color: var(--theme-primary);
outline: none;
}
.theme-template-save-form {
display: grid;
gap: 8px;
}
.theme-template-save-form label {
2026-05-29 13:30:56 +08:00
color: var(--text-primary);
font-weight: 600;
}
.theme-template-save-preview {
display: flex;
gap: 8px;
margin-top: 16px;
padding: 12px;
2026-05-29 13:30:56 +08:00
border: 1px solid var(--theme-border);
border-radius: 8px;
2026-05-29 13:30:56 +08:00
background: var(--theme-primary-soft);
}
.theme-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 0 12px;
}
.theme-color-field {
display: flex;
align-items: center;
gap: 10px;
}
.theme-color-picker {
width: 42px;
height: 34px;
padding: 0;
2026-05-29 13:30:56 +08:00
border: 1px solid var(--theme-border);
border-radius: 8px;
2026-05-29 13:30:56 +08:00
background: var(--theme-card-bg);
}
.theme-preview {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
margin-top: 8px;
padding: 16px;
border: 1px solid;
border-radius: 8px;
}
.theme-preview strong,
.theme-preview p {
display: block;
margin: 4px 0 0;
}
.theme-preview p {
font-size: 12px;
opacity: .72;
}
.theme-preview__eyebrow {
display: block;
font-size: 12px;
font-weight: 700;
}
.theme-preview__button {
flex: 0 0 auto;
padding: 9px 16px;
border-radius: 999px;
font-weight: 700;
}
.theme-view-swatches {
display: flex;
gap: 8px;
}
.theme-view-swatches span {
width: 28px;
height: 28px;
2026-05-29 13:30:56 +08:00
border: 1px solid var(--theme-border);
border-radius: 999px;
}
@media (max-width: 768px) {
.theme-section__header,
.theme-template-panel__header {
align-items: stretch;
flex-direction: column;
}
.theme-section__actions {
width: 100%;
}
.theme-grid {
grid-template-columns: 1fr;
}
}
2026-02-25 10:37:16 +08:00
</style>