index.vue 7.8 KB

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