index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <!--
  2. - Copyright (c) 2018-2025, lengleng All rights reserved.
  3. -
  4. - Redistribution and use in source and binary forms, with or without
  5. - modification, are permitted provided that the following conditions are met:
  6. -
  7. - Redistributions of source code must retain the above copyright notice,
  8. - this list of conditions and the following disclaimer.
  9. - Redistributions in binary form must reproduce the above copyright
  10. - notice, this list of conditions and the following disclaimer in the
  11. - documentation and/or other materials provided with the distribution.
  12. - Neither the name of the pig4cloud.com developer nor the names of its
  13. - contributors may be used to endorse or promote products derived from
  14. - this software without specific prior written permission.
  15. - Author: lengleng (wangiegie@gmail.com)
  16. -->
  17. <template>
  18. <div class="execution">
  19. <basic-container>
  20. <el-row :gutter="20">
  21. <el-col :span="4">
  22. <div class="grid-content bg-purple">
  23. <el-input v-model="q.nickname" placeholder="请输入昵称"/>
  24. </div>
  25. </el-col>
  26. <el-col :span="4">
  27. <div class="grid-content bg-purple">
  28. <el-select v-model="q.account" placeholder="请选择公众号">
  29. <el-option
  30. v-for="item in wxAccountList"
  31. :key="item.appid"
  32. :label="item.name"
  33. :value="item.appid"/>
  34. </el-select>
  35. </div>
  36. </el-col>
  37. <el-col :span="12">
  38. <div class="grid-content bg-purple">
  39. <el-button type="primary" icon="el-icon-search" @click="search">搜索</el-button>
  40. <el-button type="primary" icon="el-icon-sort" @click="asyncFans">同步</el-button>
  41. </div>
  42. </el-col>
  43. </el-row>
  44. <avue-crud
  45. ref="crud"
  46. :page="page"
  47. :data="tableData"
  48. :permission="permissionList"
  49. :table-loading="tableLoading"
  50. :option="tableOption"
  51. @on-load="getList"
  52. @size-change="sizeChange"
  53. @current-change="currentChange"
  54. @refresh-change="refreshChange"
  55. @row-update="handleUpdate"
  56. @row-save="handleSave"
  57. @row-del="rowDel"/>
  58. </basic-container>
  59. </div>
  60. </template>
  61. <script>
  62. import { addObj, delObj, fetchList, putObj, sync } from '@/api/mp/wxaccountfans'
  63. import { fetchAccountList } from '@/api/mp/wxaccount'
  64. import { tableOption } from '@/const/crud/mp/wxaccountfans'
  65. import { mapGetters } from 'vuex'
  66. export default {
  67. name: 'Wxaccountfans',
  68. data() {
  69. return {
  70. q: {},
  71. tableData: [],
  72. wxAccountList: [],
  73. page: {
  74. total: 0, // 总页数
  75. currentPage: 1, // 当前页数
  76. pageSize: 20 // 每页显示多少条
  77. },
  78. tableLoading: false,
  79. tableOption: tableOption
  80. }
  81. },
  82. created() {
  83. this.getAccountList()
  84. },
  85. computed: {
  86. ...mapGetters(['permissions']),
  87. permissionList() {
  88. return {
  89. addBtn: this.vaildData(this.permissions.mp_wxaccountfans_add, false),
  90. delBtn: this.vaildData(this.permissions.mp_wxaccountfans_del, false),
  91. editBtn: this.vaildData(this.permissions.mp_wxaccountfans_edit, false)
  92. }
  93. }
  94. },
  95. methods: {
  96. getAccountList() {
  97. fetchAccountList().then(response => {
  98. this.wxAccountList = response.data.data
  99. })
  100. },
  101. getList(page, params) {
  102. this.tableLoading = true
  103. fetchList(Object.assign({
  104. current: page.currentPage,
  105. size: page.pageSize
  106. }, params)).then(response => {
  107. this.tableData = response.data.data.records
  108. this.page.total = response.data.data.total
  109. this.tableLoading = false
  110. })
  111. },
  112. rowDel: function(row, index) {
  113. var _this = this
  114. this.$confirm('是否确认删除ID为' + row.id, '提示', {
  115. confirmButtonText: '确定',
  116. cancelButtonText: '取消',
  117. type: 'warning'
  118. }).then(function() {
  119. return delObj(row.id)
  120. }).then(() => {
  121. _this.tableData.splice(index, 1)
  122. _this.$message({
  123. showClose: true,
  124. message: '删除成功',
  125. type: 'success'
  126. })
  127. this.getList(this.page)
  128. }).catch(function() {
  129. })
  130. },
  131. /**
  132. * @title 数据更新
  133. * @param row 为当前的数据
  134. * @param index 为当前更新数据的行数
  135. * @param done 为表单关闭函数
  136. *
  137. **/
  138. handleUpdate: function(row, index, done) {
  139. putObj(row).then(() => {
  140. this.tableData.splice(index, 1, Object.assign({}, row))
  141. this.$message({
  142. showClose: true,
  143. message: '修改成功',
  144. type: 'success'
  145. })
  146. done()
  147. this.getList(this.page)
  148. })
  149. },
  150. /**
  151. * @title 数据添加
  152. * @param row 为当前的数据
  153. * @param done 为表单关闭函数
  154. *
  155. **/
  156. handleSave: function(row, done) {
  157. addObj(row).then(() => {
  158. this.tableData.push(Object.assign({}, row))
  159. this.$message({
  160. showClose: true,
  161. message: '添加成功',
  162. type: 'success'
  163. })
  164. done()
  165. this.getList(this.page)
  166. })
  167. },
  168. sizeChange(pageSize){
  169. this.page.pageSize = pageSize
  170. },
  171. currentChange(current){
  172. this.page.currentPage = current
  173. },
  174. refreshChange() {
  175. this.getList(this.page)
  176. },
  177. search() {
  178. this.getList(this.page, this.q)
  179. },
  180. asyncFans() {
  181. if (this.q.account) {
  182. sync(this.q.account).then(() => {
  183. this.$message({
  184. showClose: true,
  185. message: '已开始从微信同步粉丝信息,建议等待后查询',
  186. type: 'success'
  187. })
  188. })
  189. this.getList(this.page)
  190. } else {
  191. this.$message.error('请选择公众号')
  192. }
  193. }
  194. }
  195. }
  196. </script>
  197. <style lang="scss" scoped>
  198. </style>