index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. <avue-crud
  21. ref="crud"
  22. :page="page"
  23. :data="tableData"
  24. :permission="permissionList"
  25. :table-loading="tableLoading"
  26. :option="tableOption"
  27. @on-load="getList"
  28. @size-change="sizeChange"
  29. @current-change="currentChange"
  30. @refresh-change="refreshChange"
  31. @row-update="handleUpdate"
  32. @row-save="handleSave"
  33. @row-del="rowDel">
  34. <template
  35. slot-scope="scope"
  36. slot="menu">
  37. <el-button
  38. v-if="permissionList.addBtn"
  39. type="text"
  40. icon="el-icon-upload"
  41. @click="access(scope.row,scope.index)">
  42. 接入
  43. </el-button>
  44. <el-button
  45. v-if="permissionList.addBtn"
  46. type="text"
  47. icon="el-icon-check"
  48. @click="generateQr(scope.row,scope.index)">二维码
  49. </el-button>
  50. </template>
  51. </avue-crud>
  52. </basic-container>
  53. <el-dialog :visible.sync="dialogFormVisible" title="接入">
  54. <el-row :gutter="20">
  55. <el-col :span="6">服务器地址(URL)</el-col>
  56. <el-col id="target" :span="12">{{ wxurl }}</el-col>
  57. <el-col :span="6">
  58. <el-button id="btn" type="primary" style="float: right;" @click="copyLink">点击复制</el-button>
  59. </el-col>
  60. </el-row>
  61. </el-dialog>
  62. </div>
  63. </template>
  64. <script>
  65. import { addObj, delObj, fetchList, generateQr, putObj } from '@/api/mp/wxaccount'
  66. import { tableOption } from '@/const/crud/mp/wxaccount'
  67. import { mapGetters } from 'vuex'
  68. import Clipboard from 'clipboard'
  69. export default {
  70. name: 'Wxaccount',
  71. data() {
  72. return {
  73. wxurl: '',
  74. dialogFormVisible: false,
  75. tableData: [],
  76. page: {
  77. total: 0, // 总页数
  78. currentPage: 1, // 当前页数
  79. pageSize: 20 // 每页显示多少条
  80. },
  81. tableLoading: false,
  82. tableOption: tableOption
  83. }
  84. },
  85. computed: {
  86. ...mapGetters(['permissions']),
  87. permissionList() {
  88. return {
  89. addBtn: this.vaildData(this.permissions.mp_wxaccount_add, false),
  90. delBtn: this.vaildData(this.permissions.mp_wxaccount_del, false),
  91. editBtn: this.vaildData(this.permissions.mp_wxaccount_edit, false)
  92. }
  93. }
  94. },
  95. methods: {
  96. getList(page, params) {
  97. this.tableLoading = true
  98. fetchList(Object.assign({
  99. current: page.currentPage,
  100. size: page.pageSize
  101. }, params)).then(response => {
  102. this.tableData = response.data.data.records
  103. this.page.total = response.data.data.total
  104. this.tableLoading = false
  105. })
  106. },
  107. rowDel: function(row, index) {
  108. var _this = this
  109. this.$confirm('是否确认删除ID为' + row.id, '提示', {
  110. confirmButtonText: '确定',
  111. cancelButtonText: '取消',
  112. type: 'warning'
  113. }).then(function() {
  114. return delObj(row.id)
  115. }).then(() => {
  116. _this.$message.success('删除成功')
  117. this.getList(this.page)
  118. }).catch(function() {
  119. })
  120. },
  121. /**
  122. * @title 数据更新
  123. * @param row 为当前的数据
  124. * @param index 为当前更新数据的行数
  125. * @param done 为表单关闭函数
  126. *
  127. **/
  128. handleUpdate: function(row, index, done) {
  129. putObj(row).then(() => {
  130. this.$message.success('删除成功')
  131. done()
  132. this.getList(this.page)
  133. })
  134. },
  135. /**
  136. * @title 数据添加
  137. * @param row 为当前的数据
  138. * @param done 为表单关闭函数
  139. *
  140. **/
  141. handleSave: function(row, done) {
  142. row.qrUrl = undefined
  143. addObj(row).then(() => {
  144. this.$message.success('保存成功')
  145. done()
  146. this.getList(this.page)
  147. })
  148. },
  149. sizeChange(pageSize){
  150. this.page.pageSize = pageSize
  151. },
  152. currentChange(current){
  153. this.page.currentPage = current
  154. },
  155. refreshChange() {
  156. this.getList(this.page)
  157. },
  158. generateQr: function(row) {
  159. generateQr(row.appid).then(() => {
  160. this.$message.success('获取成功')
  161. this.getList(this.page)
  162. })
  163. },
  164. access: function(row) {
  165. this.dialogFormVisible = true
  166. this.wxurl = row.url + '/mp/' + row.appid + '/portal'
  167. },
  168. copyLink() {
  169. const clipboard = new Clipboard('#btn', {
  170. target: () => document.querySelector('#target')
  171. })
  172. // 复制成功执行的回调
  173. clipboard.on('success', () => {
  174. this.$message.success('复制成功')
  175. })
  176. }
  177. }
  178. }
  179. </script>
  180. <style lang="scss" scoped>
  181. </style>