index.vue 5.2 KB

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