index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <template>
  2. <!-- 搜索工作栏 -->
  3. <content-wrap>
  4. <el-form
  5. class="-mb-15px"
  6. :model="queryParams"
  7. ref="queryFormRef"
  8. :inline="true"
  9. label-width="68px"
  10. >
  11. <el-form-item label="名称" prop="name">
  12. <el-input
  13. v-model="queryParams.name"
  14. placeholder="请输入名称"
  15. clearable
  16. @keyup.enter="handleQuery"
  17. class="!w-240px"
  18. />
  19. </el-form-item>
  20. <el-form-item>
  21. <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" />搜索</el-button>
  22. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" />重置</el-button>
  23. <el-button type="primary" @click="openForm('create')" v-hasPermi="['mp:account:create']">
  24. <Icon icon="ep:plus" class="mr-5px" /> 新增
  25. </el-button>
  26. </el-form-item>
  27. </el-form>
  28. </content-wrap>
  29. <!-- 列表 -->
  30. <content-wrap>
  31. <el-table v-loading="loading" :data="list">
  32. <el-table-column label="名称" align="center" prop="name" />
  33. <el-table-column label="微信号" align="center" prop="account" width="180" />
  34. <el-table-column label="appId" align="center" prop="appId" width="180" />
  35. <el-table-column label="服务器地址(URL)" align="center" prop="appId" width="360">
  36. <template #default="scope">
  37. {{ 'http://服务端地址/mp/open/' + scope.row.appId }}
  38. </template>
  39. </el-table-column>
  40. <el-table-column label="二维码" align="center" prop="qrCodeUrl">
  41. <template #default="scope">
  42. <img
  43. v-if="scope.row.qrCodeUrl"
  44. :src="scope.row.qrCodeUrl"
  45. alt="二维码"
  46. style="height: 100px; display: inline-block"
  47. />
  48. <el-button
  49. link
  50. type="primary"
  51. @click="handleGenerateQrCode(scope.row)"
  52. v-hasPermi="['mp:account:qr-code']"
  53. >
  54. 生成二维码
  55. </el-button>
  56. </template>
  57. </el-table-column>
  58. <el-table-column label="备注" align="center" prop="remark" />
  59. <el-table-column label="操作" align="center">
  60. <template #default="scope">
  61. <el-button
  62. link
  63. type="primary"
  64. @click="openForm('update', scope.row.id)"
  65. v-hasPermi="['mp:account:update']"
  66. >
  67. 编辑
  68. </el-button>
  69. <el-button
  70. link
  71. type="danger"
  72. @click="handleDelete(scope.row.id)"
  73. v-hasPermi="['mp:account:delete']"
  74. >
  75. 删除
  76. </el-button>
  77. <el-button
  78. link
  79. type="danger"
  80. @click="handleCleanQuota(scope.row)"
  81. v-hasPermi="['mp:account:clear-quota']"
  82. >
  83. 清空 API 配额
  84. </el-button>
  85. </template>
  86. </el-table-column>
  87. </el-table>
  88. <!-- 分页组件 -->
  89. <pagination
  90. v-show="total > 0"
  91. :total="total"
  92. v-model:page="queryParams.pageNo"
  93. v-model:limit="queryParams.pageSize"
  94. @pagination="getList"
  95. />
  96. </content-wrap>
  97. <!-- 对话框(添加 / 修改) -->
  98. <AccountForm ref="formRef" @success="getList" />
  99. </template>
  100. <script setup lang="ts" name="MpAccount">
  101. import * as AccountApi from '@/api/mp/account'
  102. import AccountForm from './AccountForm.vue'
  103. const message = useMessage() // 消息弹窗
  104. const { t } = useI18n() // 国际化
  105. const loading = ref(true) // 列表的加载中
  106. const total = ref(0) // 列表的总页数
  107. const list = ref([]) // 列表的数据
  108. const queryParams = reactive({
  109. pageNo: 1,
  110. pageSize: 10,
  111. name: null,
  112. account: null,
  113. appId: null
  114. })
  115. const queryFormRef = ref() // 搜索的表单
  116. /** 查询列表 */
  117. const getList = async () => {
  118. loading.value = true
  119. // 处理查询参数
  120. let params = { ...queryParams }
  121. // 执行查询
  122. const data = await AccountApi.getAccountPage(params)
  123. list.value = data.list
  124. total.value = data.total
  125. loading.value = false
  126. }
  127. /** 搜索按钮操作 */
  128. const handleQuery = () => {
  129. queryParams.pageNo = 1
  130. getList()
  131. }
  132. /** 重置按钮操作 */
  133. const resetQuery = () => {
  134. queryFormRef.value.resetFields()
  135. handleQuery()
  136. }
  137. /** 添加/修改操作 */
  138. const formRef = ref()
  139. const openForm = (type: string, id?: number) => {
  140. formRef.value.open(type, id)
  141. }
  142. /** 删除按钮操作 */
  143. const handleDelete = async (id) => {
  144. try {
  145. // 删除的二次确认
  146. await message.delConfirm()
  147. // 发起删除
  148. await AccountApi.deleteAccount(id)
  149. message.success(t('common.delSuccess'))
  150. // 刷新列表
  151. await getList()
  152. } catch {}
  153. }
  154. /** 生成二维码的按钮操作 */
  155. const handleGenerateQrCode = async (row) => {
  156. try {
  157. // 生成二维码的二次确认
  158. await message.confirm('是否确认生成公众号账号编号为"' + row.name + '"的二维码?')
  159. // 发起生成二维码
  160. await AccountApi.generateAccountQrCode(row.id)
  161. message.success('生成二维码成功')
  162. // 刷新列表
  163. await getList()
  164. } catch {}
  165. }
  166. /** 清空二维码 API 配额的按钮操作 */
  167. const handleCleanQuota = async (row) => {
  168. try {
  169. // 清空 API 配额的二次确认
  170. await message.confirm('是否确认清空生成公众号账号编号为"' + row.name + '"的 API 配额?')
  171. // 发起清空 API 配额
  172. await AccountApi.clearAccountQuota(row.id)
  173. message.success('清空 API 配额成功')
  174. } catch {}
  175. }
  176. /** 初始化 **/
  177. onMounted(() => {
  178. getList()
  179. })
  180. </script>