Files
lgp-admin-plus/apps/web-antd/src/views/wx/template/components/import-modal.vue
年糕崽崽 0cdfb7e956
Some checks failed
CI / Test (ubuntu-latest) (push) Has been cancelled
CI / Test (windows-latest) (push) Has been cancelled
CI / Lint (ubuntu-latest) (push) Has been cancelled
CI / Lint (windows-latest) (push) Has been cancelled
CI / Check (ubuntu-latest) (push) Has been cancelled
CI / Check (windows-latest) (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
Deploy Website on push / Deploy Push Playground Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Docs Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Antd Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Element Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Naive Ftp (push) Has been cancelled
Release Drafter / update_release_draft (push) Has been cancelled
CI / CI OK (push) Has been cancelled
Deploy Website on push / Rerun on failure (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Issue Close Require / close-issues (push) Has been cancelled
Close stale issues / stale (push) Has been cancelled
更新若干功能
2026-08-20 19:18:39 +08:00

76 lines
1.9 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script lang="ts" setup>
import { ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { Alert, Input, message, Switch } from 'ant-design-vue';
import { popupData } from '#/components/crud';
import { importTemplates as doImport } from '../api';
defineOptions({
name: 'WxTemplateImportModal',
});
/**
* 导入弹窗。
* 用户粘贴导出过的 JSON含 templates 数组),后端按 strict 模式校验白名单。
*/
const jsonText = ref('');
const overwrite = ref(false);
const [Modal, modalApi] = useVbenModal({
draggable: true,
fullscreenButton: false,
onCancel() {
modalApi.close();
},
async onConfirm() {
let payload: any;
try {
payload = JSON.parse(jsonText.value);
} catch {
message.error('JSON 格式错误');
return;
}
modalApi.lock();
try {
const res = await doImport({ payload, overwrite: overwrite.value });
message.success(
`导入完成:新增 ${res.inserted},更新 ${res.updated},跳过 ${res.skipped}`,
);
popupData(modalApi).gridApi?.reload();
modalApi.close();
} finally {
modalApi.unlock();
}
},
onOpenChange(isOpen: boolean) {
if (!isOpen) return;
jsonText.value = '';
overwrite.value = false;
},
});
</script>
<template>
<Modal class="w-[640px]" title="导入模板">
<Alert
class="mb-3"
message="粘贴导出 JSON。strict 白名单:非法 tokens/layout 会被拒绝。日常请走「装修工作室」改色板与区块,勿按 template.code 特判页面。"
show-icon
type="info"
/>
<Input.Textarea
v-model:value="jsonText"
:rows="10"
placeholder="{&quot;version&quot;:1,&quot;templates&quot;:[...]}"
/>
<div class="mt-3 flex items-center gap-2">
<Switch v-model:checked="overwrite" />
<span>覆盖已存在的同 code 模板</span>
</div>
</Modal>
</template>