From 982c97ab82f3beb1b4febcf014562eda34b9fc05 Mon Sep 17 00:00:00 2001
From: liu <2021943741@qq.com>
Date: 星期二, 29 九月 2026 17:59:41 +0800
Subject: [PATCH] feat(ui): 江苏商贸品牌视觉与首页/登录页改版
---
src/views/wxcp/components/push-scope-picker.vue | 172 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 172 insertions(+), 0 deletions(-)
diff --git a/src/views/wxcp/components/push-scope-picker.vue b/src/views/wxcp/components/push-scope-picker.vue
new file mode 100644
index 0000000..51d5e99
--- /dev/null
+++ b/src/views/wxcp/components/push-scope-picker.vue
@@ -0,0 +1,172 @@
+<script lang="ts" setup>
+import type { WxCpMemberApi } from '#/api/wxcp/member';
+
+import { computed, onMounted, ref, watch } from 'vue';
+
+import { Alert, Radio, Select, Spin } from 'ant-design-vue';
+
+import {
+ getWxCpDepartmentList,
+ getWxCpMemberList,
+} from '#/api/wxcp/member';
+
+import { PUSH_SCOPE_OPTIONS, PUSH_SCOPE } from '../data';
+
+defineOptions({ name: 'WxCpPushScopePicker' });
+
+interface Props {
+ /** 鎺ㄩ�佽寖鍥达細0鍏ㄥ憳 1鎸囧畾閮ㄩ棬 2鎸囧畾鎴愬憳 */
+ scope?: number;
+ /** 鎺ㄩ�佺洰鏍囷紝閫楀彿鍒嗛殧锛涜寖鍥存槸鍏ㄥ憳鏃舵棤鎰忎箟 */
+ target?: string;
+ disabled?: boolean;
+}
+
+const props = withDefaults(defineProps<Props>(), {
+ scope: PUSH_SCOPE.ALL,
+ target: '',
+ disabled: false,
+});
+
+const emit = defineEmits<{
+ 'update:scope': [value: number];
+ 'update:target': [value: string];
+}>();
+
+/** 閫氳褰曟暟鎹細鍙湪棣栨闇�瑕佹椂鎷夊彇锛岄伩鍏嶆瘡娆℃墦寮�寮圭獥閮芥墦浼佷笟寰俊鎺ュ彛 */
+const departments = ref<WxCpMemberApi.Department[]>([]);
+const members = ref<WxCpMemberApi.Member[]>([]);
+const loading = ref(false);
+const loaded = ref(false);
+const loadError = ref('');
+
+async function ensureContacts() {
+ if (loaded.value || loading.value) {
+ return;
+ }
+ loading.value = true;
+ loadError.value = '';
+ try {
+ const [deptList, memberList] = await Promise.all([
+ getWxCpDepartmentList(),
+ getWxCpMemberList({ fetchChild: true }),
+ ]);
+ departments.value = deptList ?? [];
+ members.value = memberList ?? [];
+ loaded.value = true;
+ } catch (error: unknown) {
+ loadError.value =
+ (error as Error)?.message || '鍔犺浇浼佷笟寰俊閫氳褰曞け璐ワ紝璇风◢鍚庨噸璇�';
+ } finally {
+ loading.value = false;
+ }
+}
+
+// 閫夊埌闇�瑕侀�氳褰曠殑鑼冨洿鏃舵墠鍔犺浇
+watch(
+ () => props.scope,
+ (scope) => {
+ if (scope === PUSH_SCOPE.PARTY || scope === PUSH_SCOPE.USER) {
+ ensureContacts();
+ }
+ },
+);
+
+onMounted(() => {
+ if (props.scope === PUSH_SCOPE.PARTY || props.scope === PUSH_SCOPE.USER) {
+ ensureContacts();
+ }
+});
+
+const deptOptions = computed(() =>
+ departments.value.map((d) => ({ label: d.name || `閮ㄩ棬${d.id}`, value: d.id })),
+);
+
+const memberOptions = computed(() =>
+ members.value.map((m) => ({
+ label: m.name ? `${m.name}锛�${m.userId}锛塦 : m.userId,
+ value: m.userId,
+ })),
+);
+
+/** 鐩爣瀛楃涓� <-> 鏁扮粍 */
+const selected = computed<string[] | number[]>({
+ get() {
+ const raw = (props.target || '').trim();
+ if (!raw) {
+ return [];
+ }
+ const parts = raw
+ .split(/[,锛宂/)
+ .map((s) => s.trim())
+ .filter(Boolean);
+ // 閮ㄩ棬鐢ㄦ暟瀛楋紝鎴愬憳鐢ㄥ瓧绗︿覆锛堟垚鍛樿处鍙锋槸 LiuYi 杩欑锛�
+ return props.scope === PUSH_SCOPE.PARTY
+ ? parts.map((p) => Number(p)).filter((n) => Number.isFinite(n))
+ : parts;
+ },
+ set(value) {
+ emit('update:target', (value as (number | string)[]).join(','));
+ },
+});
+
+function handleScopeChange(e: unknown) {
+ const value = Number((e as { target?: { value?: number } })?.target?.value);
+ emit('update:scope', Number.isFinite(value) ? value : PUSH_SCOPE.ALL);
+ // 鍒囨崲鑼冨洿鏃舵竻鎺夋棫鐩爣锛岄伩鍏嶆妸鎴愬憳璐﹀彿褰撴垚閮ㄩ棬ID鎻愪氦
+ emit('update:target', '');
+}
+</script>
+
+<template>
+ <div>
+ <Radio.Group
+ :value="scope"
+ :disabled="disabled"
+ button-style="solid"
+ @change="handleScopeChange"
+ >
+ <Radio.Button
+ v-for="opt in PUSH_SCOPE_OPTIONS"
+ :key="opt.value"
+ :value="opt.value"
+ >
+ {{ opt.label }}
+ </Radio.Button>
+ </Radio.Group>
+
+ <div v-if="scope !== PUSH_SCOPE.ALL" class="mt-3">
+ <Spin :spinning="loading">
+ <Alert
+ v-if="loadError"
+ :message="loadError"
+ type="warning"
+ show-icon
+ class="mb-2"
+ />
+ <Select
+ v-model:value="selected"
+ :options="scope === PUSH_SCOPE.PARTY ? deptOptions : memberOptions"
+ :disabled="disabled || !!loadError"
+ :mode="scope === PUSH_SCOPE.PARTY ? 'multiple' : 'multiple'"
+ :placeholder="
+ scope === PUSH_SCOPE.PARTY
+ ? '璇烽�夋嫨閮ㄩ棬锛屽彲澶氶��'
+ : '璇烽�夋嫨鎴愬憳锛屽彲澶氶��'
+ "
+ option-filter-prop="label"
+ show-search
+ allow-clear
+ class="w-full"
+ />
+ </Spin>
+ <div class="mt-2 text-xs text-gray-400">
+ {{
+ scope === PUSH_SCOPE.PARTY
+ ? '鎺ㄩ�佺粰鎵�閫夐儴闂ㄤ笅鐨勫叏閮ㄦ垚鍛�'
+ : '鎺ㄩ�佺粰鎵�閫夋垚鍛橈紝璐﹀彿鏉ヨ嚜浼佷笟寰俊閫氳褰�'
+ }}
+ </div>
+ </div>
+ </div>
+</template>
--
Gitblit v1.9.3