index.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <template>
  2. <doc-alert title="公众号粉丝" url="https://doc.iocoder.cn/mp/user/" />
  3. <!-- 搜索工作栏 -->
  4. <ContentWrap>
  5. <el-form
  6. class="-mb-15px"
  7. :model="queryParams"
  8. ref="queryFormRef"
  9. :inline="true"
  10. label-width="68px"
  11. >
  12. <el-form-item label="公众号" prop="accountId">
  13. <WxAccountSelect @change="onAccountChanged" />
  14. </el-form-item>
  15. <el-form-item label="用户标识" prop="openid">
  16. <el-input
  17. v-model="queryParams.openid"
  18. placeholder="请输入用户标识"
  19. clearable
  20. @keyup.enter="handleQuery"
  21. class="!w-240px"
  22. />
  23. </el-form-item>
  24. <el-form-item label="昵称" prop="nickname">
  25. <el-input
  26. v-model="queryParams.nickname"
  27. placeholder="请输入昵称"
  28. clearable
  29. @keyup.enter="handleQuery"
  30. class="!w-240px"
  31. />
  32. </el-form-item>
  33. <el-form-item>
  34. <el-button @click="handleQuery"> <Icon icon="ep:search" />搜索 </el-button>
  35. <el-button @click="resetQuery"> <Icon icon="ep:refresh" />重置 </el-button>
  36. <el-button type="success" plain @click="handleSync" v-hasPermi="['mp:user:sync']">
  37. <Icon icon="ep:refresh" class="mr-5px" /> 同步
  38. </el-button>
  39. </el-form-item>
  40. </el-form>
  41. </ContentWrap>
  42. <!-- 列表 -->
  43. <ContentWrap>
  44. <el-table v-loading="loading" :data="list">
  45. <el-table-column label="编号" align="center" prop="id" />
  46. <el-table-column label="用户标识" align="center" prop="openid" width="260" />
  47. <el-table-column label="昵称" align="center" prop="nickname" />
  48. <el-table-column label="备注" align="center" prop="remark" />
  49. <el-table-column label="标签" align="center" prop="tagIds" width="200">
  50. <template #default="scope">
  51. <span v-for="(tagId, index) in scope.row.tagIds" :key="index">
  52. <el-tag>{{ tagList.find((tag) => tag.tagId === tagId)?.name }} </el-tag>&nbsp;
  53. </span>
  54. </template>
  55. </el-table-column>
  56. <el-table-column label="订阅状态" align="center" prop="subscribeStatus">
  57. <template #default="scope">
  58. <el-tag v-if="scope.row.subscribeStatus === 0" type="success">已订阅</el-tag>
  59. <el-tag v-else type="danger">未订阅</el-tag>
  60. </template>
  61. </el-table-column>
  62. <el-table-column
  63. label="订阅时间"
  64. align="center"
  65. prop="subscribeTime"
  66. width="180"
  67. :formatter="dateFormatter"
  68. />
  69. <el-table-column label="操作" align="center">
  70. <template #default="scope">
  71. <el-button
  72. type="primary"
  73. link
  74. @click="openForm(scope.row.id)"
  75. v-hasPermi="['mp:user:update']"
  76. >
  77. 修改
  78. </el-button>
  79. </template>
  80. </el-table-column>
  81. </el-table>
  82. <!-- 分页 -->
  83. <Pagination
  84. :total="total"
  85. v-model:page="queryParams.pageNo"
  86. v-model:limit="queryParams.pageSize"
  87. @pagination="getList"
  88. />
  89. </ContentWrap>
  90. <!-- 表单弹窗:修改 -->
  91. <UserForm ref="formRef" @success="getList" />
  92. </template>
  93. <script lang="ts" setup name="MpUser">
  94. import { dateFormatter } from '@/utils/formatTime'
  95. import * as MpUserApi from '@/api/mp/user'
  96. import * as MpTagApi from '@/api/mp/tag'
  97. import WxAccountSelect from '@/views/mp/components/wx-account-select/main.vue'
  98. import type { FormInstance } from 'element-plus'
  99. import UserForm from './UserForm.vue'
  100. const message = useMessage() // 消息
  101. const loading = ref(true) // 列表的加载中
  102. const total = ref(0) // 列表的总页数
  103. const list = ref<any[]>([]) // 列表的数据
  104. interface QueryParams {
  105. pageNo: number
  106. pageSize: number
  107. accountId?: number
  108. openid: string | null
  109. nickname: string | null
  110. }
  111. const queryParams: QueryParams = reactive({
  112. pageNo: 1,
  113. pageSize: 10,
  114. accountId: undefined,
  115. openid: null,
  116. nickname: null
  117. })
  118. const queryFormRef = ref<FormInstance | null>(null) // 搜索的表单
  119. const tagList = ref<any[]>([]) // 公众号标签列表
  120. /** 侦听公众号变化 **/
  121. const onAccountChanged = (id?: number) => {
  122. queryParams.pageNo = 1
  123. queryParams.accountId = id
  124. getList()
  125. }
  126. /** 查询列表 */
  127. const getList = async () => {
  128. try {
  129. loading.value = true
  130. const data = await MpUserApi.getUserPage(queryParams)
  131. list.value = data.list
  132. total.value = data.total
  133. } finally {
  134. loading.value = false
  135. }
  136. }
  137. /** 搜索按钮操作 */
  138. const handleQuery = () => {
  139. queryParams.pageNo = 1
  140. getList()
  141. }
  142. /** 重置按钮操作 */
  143. const resetQuery = () => {
  144. const accountId = queryParams.accountId
  145. queryFormRef.value?.resetFields()
  146. queryParams.accountId = accountId
  147. handleQuery()
  148. }
  149. /** 添加/修改操作 */
  150. const formRef = ref<InstanceType<typeof UserForm> | null>(null)
  151. const openForm = (id: number) => {
  152. formRef.value?.open(id)
  153. }
  154. /** 同步标签 */
  155. const handleSync = async () => {
  156. try {
  157. await message.confirm('是否确认同步粉丝?')
  158. await MpUserApi.syncUser(queryParams.accountId)
  159. message.success('开始从微信公众号同步粉丝信息,同步需要一段时间,建议稍后再查询')
  160. await getList()
  161. } catch {}
  162. }
  163. /** 初始化 */
  164. onMounted(async () => {
  165. tagList.value = await MpTagApi.getSimpleTagList()
  166. })
  167. </script>