index.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <template>
  2. <div class="app-container">
  3. <doc-alert title="公众号粉丝" url="https://doc.iocoder.cn/mp/user/" />
  4. <!-- 搜索工作栏 -->
  5. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
  6. <el-form-item label="公众号" prop="accountId">
  7. <el-select v-model="queryParams.accountId" placeholder="请选择公众号">
  8. <el-option v-for="item in accounts" :key="parseInt(item.id)" :label="item.name" :value="parseInt(item.id)" />
  9. </el-select>
  10. </el-form-item>
  11. <el-form-item label="用户标识" prop="openid">
  12. <el-input v-model="queryParams.openid" placeholder="请输入用户标识" clearable @keyup.enter.native="handleQuery"/>
  13. </el-form-item>
  14. <el-form-item label="昵称" prop="nickname">
  15. <el-input v-model="queryParams.nickname" placeholder="请输入昵称" clearable @keyup.enter.native="handleQuery"/>
  16. </el-form-item>
  17. <el-form-item>
  18. <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
  19. <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
  20. </el-form-item>
  21. </el-form>
  22. <!-- 操作工具栏 -->
  23. <el-row :gutter="10" class="mb8">
  24. <el-col :span="1.5">
  25. <el-button type="info" plain icon="el-icon-refresh" size="mini" @click="handleSync"
  26. v-hasPermi="['mp:fans:sync']">同步
  27. </el-button>
  28. </el-col>
  29. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  30. </el-row>
  31. <!-- 列表 -->
  32. <el-table v-loading="loading" :data="list">
  33. <el-table-column label="编号" align="center" prop="id" />
  34. <el-table-column label="用户标识" align="center" prop="openid" width="260" />
  35. <el-table-column label="昵称" align="center" prop="nickname" />
  36. <el-table-column label="备注" align="center" prop="remark" />
  37. <el-table-column label="标签" align="center" prop="tagIds" width="200">
  38. <template slot-scope="scope">
  39. <span v-for="(tagId, index) in scope.row.tagIds" :key="index">
  40. <el-tag>{{ tags.find(tag => tag.tagId === tagId)?.name }} </el-tag>&nbsp;
  41. </span>
  42. </template>
  43. </el-table-column>
  44. <el-table-column label="订阅状态" align="center" prop="subscribeStatus">
  45. <template slot-scope="scope">
  46. <el-tag v-if="scope.row.subscribeStatus === 0" type="success">已订阅</el-tag>
  47. <el-tag v-else type="danger">未订阅</el-tag>
  48. </template>
  49. </el-table-column>
  50. <el-table-column label="订阅时间" align="center" prop="subscribeTime" width="180">
  51. <template slot-scope="scope">
  52. <span>{{ parseTime(scope.row.subscribeTime) }}</span>
  53. </template>
  54. </el-table-column>
  55. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  56. <template slot-scope="scope">
  57. <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
  58. v-hasPermi="['mp:fans:update']">修改</el-button>
  59. </template>
  60. </el-table-column>
  61. </el-table>
  62. <!-- 分页组件 -->
  63. <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
  64. @pagination="getList"/>
  65. <!-- 对话框(添加 / 修改) -->
  66. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  67. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  68. <el-form-item label="昵称" prop="nickname">
  69. <el-input v-model="form.nickname" placeholder="请输入昵称" />
  70. </el-form-item>
  71. <el-form-item label="备注" prop="remark">
  72. <el-input v-model="form.remark" placeholder="请输入备注" />
  73. </el-form-item>
  74. <el-form-item label="标签" prop="tagIds">
  75. <el-select v-model="form.tagIds" multiple clearable placeholder="请选择标签">
  76. <el-option v-for="item in tags" :key="parseInt(item.tagId)" :label="item.name" :value="parseInt(item.tagId)" />
  77. </el-select>
  78. </el-form-item>
  79. </el-form>
  80. <div slot="footer" class="dialog-footer">
  81. <el-button type="primary" @click="submitForm">确 定</el-button>
  82. <el-button @click="cancel">取 消</el-button>
  83. </div>
  84. </el-dialog>
  85. </div>
  86. </template>
  87. <script>
  88. import { updateUser, getUser, getUserPage, syncUser } from "@/api/mp/user";
  89. import { getSimpleAccounts } from "@/api/mp/account";
  90. import { getSimpleTags } from "@/api/mp/tag";
  91. export default {
  92. name: "WxAccountFans",
  93. components: {
  94. },
  95. data() {
  96. return {
  97. // 遮罩层
  98. loading: true,
  99. // 显示搜索条件
  100. showSearch: true,
  101. // 总条数
  102. total: 0,
  103. // 微信公众号粉丝列表
  104. list: [],
  105. // 弹出层标题
  106. title: "",
  107. // 是否显示弹出层
  108. open: false,
  109. // 查询参数
  110. queryParams: {
  111. pageNo: 1,
  112. pageSize: 10,
  113. accountId: null,
  114. openid: null,
  115. nickname: null,
  116. },
  117. // 表单参数
  118. form: {},
  119. // 表单校验
  120. rules: {},
  121. // 公众号账号列表
  122. accounts: [],
  123. // 公众号标签列表
  124. tags: [],
  125. };
  126. },
  127. created() {
  128. getSimpleAccounts().then(response => {
  129. this.accounts = response.data;
  130. // 默认选中第一个
  131. if (this.accounts.length > 0) {
  132. this.queryParams.accountId = this.accounts[0].id;
  133. }
  134. // 加载数据
  135. this.getList();
  136. })
  137. // 加载标签
  138. getSimpleTags().then(response => {
  139. this.tags = response.data;
  140. })
  141. },
  142. methods: {
  143. /** 查询列表 */
  144. getList() {
  145. // 如果没有选中公众号账号,则进行提示。
  146. if (!this.queryParams.accountId) {
  147. this.$message.error('未选中公众号,无法查询用户')
  148. return false
  149. }
  150. this.loading = true;
  151. // 处理查询参数
  152. let params = {...this.queryParams};
  153. // 执行查询
  154. getUserPage(params).then(response => {
  155. this.list = response.data.list;
  156. this.total = response.data.total;
  157. this.loading = false;
  158. });
  159. },
  160. /** 取消按钮 */
  161. cancel() {
  162. this.open = false;
  163. this.reset();
  164. },
  165. /** 表单重置 */
  166. reset() {
  167. this.form = {
  168. id: undefined,
  169. nickname: undefined,
  170. remark: undefined,
  171. tagIds: [],
  172. };
  173. this.resetForm("form");
  174. },
  175. /** 搜索按钮操作 */
  176. handleQuery() {
  177. this.queryParams.pageNo = 1;
  178. this.getList();
  179. },
  180. /** 重置按钮操作 */
  181. resetQuery() {
  182. this.resetForm("queryForm");
  183. // 默认选中第一个
  184. if (this.accounts.length > 0) {
  185. this.queryParams.accountId = this.accounts[0].id;
  186. }
  187. this.handleQuery();
  188. },
  189. /** 修改按钮操作 */
  190. handleUpdate(row) {
  191. this.reset();
  192. const id = row.id;
  193. getUser(id).then(response => {
  194. this.form = response.data;
  195. this.open = true;
  196. this.title = "修改公众号粉丝";
  197. });
  198. },
  199. /** 提交按钮 */
  200. submitForm() {
  201. this.$refs["form"].validate(valid => {
  202. if (!valid) {
  203. return;
  204. }
  205. // 修改的提交
  206. if (this.form.id != null) {
  207. updateUser(this.form).then(response => {
  208. this.$modal.msgSuccess("修改成功");
  209. this.open = false;
  210. this.getList();
  211. });
  212. }
  213. });
  214. },
  215. /** 同步标签 */
  216. handleSync() {
  217. const accountId = this.queryParams.accountId
  218. this.$modal.confirm('是否确认同步粉丝?').then(function () {
  219. return syncUser(accountId)
  220. }).then(() => {
  221. this.$modal.msgSuccess('开始从微信公众号同步粉丝信息,同步需要一段时间,建议稍后再查询')
  222. }).catch(() => {
  223. })
  224. },
  225. }
  226. };
  227. </script>