feat: 自动回复迁移

This commit is contained in:
hw
2025-11-04 16:53:08 +08:00
parent 7a5f4b01e2
commit 84795d10cd
28 changed files with 2060 additions and 103 deletions

View File

@@ -1,7 +1,7 @@
<script lang="ts" setup>
import type { MpAccountApi } from '#/api/mp/account';
import { onMounted, reactive, ref, unref } from 'vue';
import { computed, onMounted, reactive, ref, unref, watch } from 'vue';
import { useRouter } from 'vue-router';
import { ElMessage } from 'element-plus';
@@ -11,8 +11,13 @@ import { useTagsViewStore } from '#/store/tagsView';
defineOptions({ name: 'WxAccountSelect' });
const props = defineProps<{
modelValue?: number;
}>();
const emit = defineEmits<{
(e: 'change', id: number, name: string): void;
(e: 'update:modelValue', id: number): void;
}>();
const message = ElMessage; // 消息弹窗
@@ -26,6 +31,51 @@ const account: MpAccountApi.AccountSimple = reactive({
const accountList = ref<MpAccountApi.AccountSimple[]>([]);
// 计算当前选中的 ID优先使用 modelValue表单绑定否则使用内部 account.id
const currentId = computed({
get: () => {
// 如果外部传入了 modelValue优先使用外部的值
if (props.modelValue !== undefined && props.modelValue !== null) {
return props.modelValue;
}
return account.id;
},
set: (value: number) => {
// 更新内部状态
account.id = value;
// 同步到外部(表单系统)
emit('update:modelValue', value);
// 触发 change 事件(保持向后兼容)
const found = accountList.value.find(
(v: MpAccountApi.AccountSimple) => v.id === value,
);
if (found) {
account.name = found.name;
emit('change', value, found.name);
}
},
});
// 监听外部 modelValue 变化,同步到内部状态
watch(
() => props.modelValue,
(newValue) => {
if (
newValue !== undefined &&
newValue !== null &&
newValue !== account.id
) {
account.id = newValue;
const found = accountList.value.find(
(v: MpAccountApi.AccountSimple) => v.id === newValue,
);
if (found) {
account.name = found.name;
}
}
},
);
/** 查询公众号列表 */
async function handleQuery() {
accountList.value = await getSimpleAccountList();
@@ -35,25 +85,31 @@ async function handleQuery() {
await push({ name: 'MpAccount' });
return;
}
// 默认选中第一个
const firstAccount = accountList.value[0];
if (firstAccount) {
account.id = firstAccount.id;
if (account.id) {
// 如果外部没有传入值modelValue 为空),默认选中第一个
if (props.modelValue === undefined || props.modelValue === null) {
const firstAccount = accountList.value[0];
if (firstAccount) {
currentId.value = firstAccount.id;
account.name = firstAccount.name;
emit('change', account.id, account.name);
emit('change', firstAccount.id, firstAccount.name);
}
} else {
// 如果外部有值,同步到内部状态
const found = accountList.value.find(
(v: MpAccountApi.AccountSimple) => v.id === props.modelValue,
);
if (found) {
account.id = props.modelValue;
account.name = found.name;
}
}
}
/** 公众号变化 */
function onChanged(id?: number) {
const found = accountList.value.find(
(v: MpAccountApi.AccountSimple) => v.id === id,
);
if (account.id && found) {
account.name = found.name;
emit('change', account.id, account.name);
if (id) {
currentId.value = id;
}
}
@@ -65,7 +121,7 @@ onMounted(() => {
<template>
<el-select
v-model="account.id"
v-model="currentId"
placeholder="请选择公众号"
class="!w-240px"
@change="onChanged"

View File

@@ -13,9 +13,9 @@
<script lang="ts" setup>
import { ref } from 'vue';
// import { VideoPlayer } from '@videojs-player/vue';
import { VideoPlayer } from '@videojs-player/vue';
// import 'video.js/dist/video-js.css';
import 'video.js/dist/video-js.css';
defineOptions({ name: 'WxVideoPlayer' });
@@ -52,7 +52,6 @@ const playVideo = () => {
class="video-player vjs-big-play-centered"
:src="props.url"
poster=""
crossorigin="anonymous"
controls
playsinline
:volume="0.6"