index.vue 5.4 KB

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