From a1d7e81859f554f3a53680cc35f0f49bf1f77098 Mon Sep 17 00:00:00 2001
From: wwf <1971391498@qq.com>
Date: 星期四, 14 五月 2026 14:37:02 +0800
Subject: [PATCH] 导入项目

---
 src/views/mp/user/index.vue |  225 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 225 insertions(+), 0 deletions(-)

diff --git a/src/views/mp/user/index.vue b/src/views/mp/user/index.vue
new file mode 100644
index 0000000..431e1c6
--- /dev/null
+++ b/src/views/mp/user/index.vue
@@ -0,0 +1,225 @@
+<template>
+  <doc-alert title="鍏紬鍙风矇涓�" url="https://doc.iocoder.cn/mp/user/" />
+
+  <!-- 鎼滅储宸ヤ綔鏍� -->
+  <ContentWrap>
+    <el-form
+      class="-mb-15px"
+      :model="queryParams"
+      ref="queryFormRef"
+      :inline="true"
+      label-width="68px"
+    >
+      <el-form-item label="鍏紬鍙�" prop="accountId">
+        <WxAccountSelect @change="onAccountChanged" :modelValue="queryParams.accountId" />
+      </el-form-item>
+      <el-form-item label="鐢ㄦ埛鏍囪瘑" prop="openid">
+        <el-input
+          v-model="queryParams.openid"
+          placeholder="璇疯緭鍏ョ敤鎴锋爣璇�"
+          clearable
+          @keyup.enter="handleQuery"
+          class="!w-240px"
+        />
+      </el-form-item>
+      <el-form-item label="鏄电О" prop="nickname">
+        <el-input
+          v-model="queryParams.nickname"
+          placeholder="璇疯緭鍏ユ樀绉�"
+          clearable
+          @keyup.enter="handleQuery"
+          class="!w-240px"
+        />
+      </el-form-item>
+      <el-form-item>
+        <el-button @click="handleQuery"> <Icon icon="ep:search" />鎼滅储 </el-button>
+        <el-button @click="resetQuery"> <Icon icon="ep:refresh" />閲嶇疆 </el-button>
+        <el-button
+          type="success"
+          plain
+          @click="handleSync"
+          v-hasPermi="['mp:user:sync']"
+          :disabled="queryParams.accountId === 0"
+        >
+          <Icon icon="ep:refresh" class="mr-5px" /> 鍚屾
+        </el-button>
+      </el-form-item>
+    </el-form>
+  </ContentWrap>
+
+  <!-- 鍒楄〃 -->
+  <ContentWrap>
+    <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange">
+      <el-table-column type="selection" width="55" v-if="isDialog"/>
+      <el-table-column label="缂栧彿" align="center" prop="id" />
+      <el-table-column label="鐢ㄦ埛鏍囪瘑" align="center" prop="openid" width="260" />
+      <el-table-column label="鐢ㄦ埛澶村儚" min-width="80px" prop="headImageUrl">
+        <template #default="scope">
+          <el-avatar :src="scope.row.headImageUrl"/>
+        </template>
+      </el-table-column>
+      <el-table-column label="鏄电О" align="center" prop="nickname" />
+      <el-table-column label="澶囨敞" align="center" prop="remark" />
+      <el-table-column label="鏍囩" align="center" prop="tagIds" width="200">
+        <template #default="scope">
+          <span v-for="(tagId, index) in scope.row.tagIds" :key="index">
+            <el-tag>{{ tagList.find((tag) => tag.tagId === tagId)?.name }} </el-tag>&nbsp;
+          </span>
+        </template>
+      </el-table-column>
+      <el-table-column label="璁㈤槄鐘舵��" align="center" prop="subscribeStatus">
+        <template #default="scope">
+          <el-tag v-if="scope.row.subscribeStatus === 0" type="success">宸茶闃�</el-tag>
+          <el-tag v-else type="danger">鏈闃�</el-tag>
+        </template>
+      </el-table-column>
+      <el-table-column
+        label="璁㈤槄鏃堕棿"
+        align="center"
+        prop="subscribeTime"
+        width="180"
+        :formatter="dateFormatter"
+      />
+      <el-table-column label="鎿嶄綔" align="center">
+        <template #default="scope">
+          <el-button
+            type="primary"
+            link
+            @click="openForm(scope.row.id)"
+            v-hasPermi="['mp:user:update']"
+          >
+            淇敼
+          </el-button>
+        </template>
+      </el-table-column>
+    </el-table>
+    <!-- 鍒嗛〉 -->
+    <Pagination
+      :total="total"
+      v-model:page="queryParams.pageNo"
+      v-model:limit="queryParams.pageSize"
+      @pagination="getList"
+    />
+  </ContentWrap>
+
+  <!-- 琛ㄥ崟寮圭獥锛氫慨鏀� -->
+  <UserForm ref="formRef" @success="getList" />
+</template>
+<script lang="ts" setup>
+import {dateFormatter} from '@/utils/formatTime'
+import * as MpUserApi from '@/api/mp/user'
+import * as MpTagApi from '@/api/mp/tag'
+import WxAccountSelect from '@/views/mp/components/wx-account-select'
+import type {FormInstance} from 'element-plus'
+import UserForm from './UserForm.vue'
+import {ref} from "vue";
+
+defineOptions({ name: 'MpUser' })
+
+const { t } = useI18n() // 鍥介檯鍖�
+const message = useMessage() // 娑堟伅
+
+const isDialog = ref(false) // 鏄笉鏄脊绐楄皟鐢�
+const loading = ref(true) // 鍒楄〃鐨勫姞杞戒腑
+const total = ref(0) // 鍒楄〃鐨勬�婚〉鏁�
+const list = ref<any[]>([]) // 鍒楄〃鐨勬暟鎹�
+const multipleSelection = ref<String[]>([])
+
+const queryParams = reactive({
+  pageNo: 1,
+  pageSize: 10,
+  accountId: -1,
+  openid: '',
+  nickname: ''
+})
+const queryFormRef = ref<FormInstance | null>(null) // 鎼滅储鐨勮〃鍗�
+const tagList = ref<any[]>([]) // 鍏紬鍙锋爣绛惧垪琛�
+
+/** 渚﹀惉鍏紬鍙峰彉鍖� **/
+const onAccountChanged = (id: number) => {
+  queryParams.accountId = id
+  queryParams.pageNo = 1
+  getList()
+}
+
+/** 鏌ヨ鍒楄〃 */
+const getList = async () => {
+  try {
+    multipleSelection.value = []
+    loading.value = true
+    const data = await MpUserApi.getUserPage(queryParams)
+    list.value = data.list
+    total.value = data.total
+  } finally {
+    loading.value = false
+  }
+}
+
+/** 鎼滅储鎸夐挳鎿嶄綔 */
+const handleQuery = () => {
+  queryParams.pageNo = 1
+  getList()
+  if(isDialog.value){
+    emitChange()
+  }
+}
+
+/** 閲嶇疆鎸夐挳鎿嶄綔 */
+const resetQuery = () => {
+  const accountId = queryParams.accountId
+  queryFormRef.value?.resetFields()
+  queryParams.accountId = accountId
+  handleQuery()
+}
+
+/** 娣诲姞/淇敼鎿嶄綔 */
+const formRef = ref<InstanceType<typeof UserForm> | null>(null)
+const openForm = (id: number) => {
+  formRef.value?.open(id)
+}
+
+/** 鍚屾鏍囩 */
+const handleSync = async () => {
+  try {
+    await message.confirm('鏄惁纭鍚屾绮変笣锛�')
+    await MpUserApi.syncUser(queryParams.accountId)
+    message.success('寮�濮嬩粠寰俊鍏紬鍙峰悓姝ョ矇涓濅俊鎭紝鍚屾闇�瑕佷竴娈垫椂闂达紝寤鸿绋嶅悗鍐嶆煡璇�')
+    await getList()
+  } catch {}
+}
+
+/** Expose*/
+defineExpose({
+  open: (accountId: number) => {
+    onAccountChanged(accountId)
+    isDialog.value = true
+  }
+});
+
+/** Emits*/
+interface Emits {
+  (e: 'change', data: {
+    multipleSelection: any[]
+    total: number
+    queryParams: object
+  }): void
+  // (e: 'select', user: any): void
+  // (e: 'cancel'): void
+}
+const emit = defineEmits<Emits>()
+const emitChange = () => {
+  emit('change', {multipleSelection: multipleSelection.value, total: total.value, queryParams})
+}
+
+const handleSelectionChange = (val: any[]) => {
+  multipleSelection.value = val
+  if (isDialog.value) {
+    emitChange()
+  }
+}
+
+/** 鍒濆鍖� */
+onMounted(async () => {
+  tagList.value = await MpTagApi.getSimpleTagList()
+})
+</script>

--
Gitblit v1.8.0