index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <template>
  2. <div class="default-main ba-table-box">
  3. <!-- 表格顶部菜单 -->
  4. <TableHeader :buttons="['refresh','columnDisplay']">
  5. <el-form style="margin-left: 5px;padding-top: 20px;" inline :model="seachForm" @submit.prevent="handleSearch">
  6. <el-form-item>
  7. <el-input v-model="seachForm.name" placeholder="请输入配置名称" @blur="handleSearch" clearable />
  8. </el-form-item>
  9. <el-form-item>
  10. <el-select v-model="seachForm.type" placeholder="请选择支付类型" style="width: 150px;" clearable filterable @change="handleSearch">
  11. <el-option value="1" label="微信支付" />
  12. <el-option value="2" label="支付宝支付" />
  13. </el-select>
  14. </el-form-item>
  15. <el-form-item>
  16. <el-select v-model="seachForm.status" placeholder="请选择状态" style="width: 150px;" clearable filterable @change="handleSearch">
  17. <el-option label="禁用" value="0" />
  18. <el-option label="启用" value="1" />
  19. </el-select>
  20. </el-form-item>
  21. <el-form-item>
  22. <el-button type="primary" @click="onAdd" v-auth="'edit'">添加</el-button>
  23. </el-form-item>
  24. </el-form>
  25. </TableHeader>
  26. <!-- 表格 -->
  27. <!-- 要使用`el-table`组件原有的属性,直接加在Table标签上即可 -->
  28. <Table ref="tableRef">
  29. <template #operate>
  30. <el-table-column prop="operate" align="center" label="操作" min-width="150" fixed="right">
  31. <template #default="scope">
  32. <el-button type="primary" size="small" @click="onEdit(scope.row)" v-auth="'edit'">编辑</el-button>
  33. <el-button type="danger" size="small" @click="handleDel(scope.row)" v-auth="'delete'">删除</el-button>
  34. </template>
  35. </el-table-column>
  36. </template>
  37. </Table>
  38. <!-- 表单 -->
  39. <PopupForm @success="baTable.getIndex()" />
  40. </div>
  41. </template>
  42. <script setup lang="ts">
  43. import { ref, reactive, provide, useTemplateRef } from 'vue'
  44. import baTableClass from '/@/utils/baTable'
  45. import Table from '/@/components/table/index.vue'
  46. import TableHeader from '/@/components/table/header/index.vue'
  47. import PopupForm from './popupForm.vue'
  48. import { baTableApi } from '/@/api/common'
  49. import { useI18n } from 'vue-i18n'
  50. import { cloneDeep } from 'lodash-es'
  51. import { ElMessageBox } from 'element-plus'
  52. import { del } from '/@/api/backend/pay/config'
  53. defineOptions({
  54. name: 'pay/config',
  55. })
  56. const { t } = useI18n()
  57. const seachForm = reactive({
  58. name: "",
  59. type: "",
  60. status: ""
  61. })
  62. // 搜索
  63. const handleSearch = () => {
  64. baTable.table.filter!.page = 1
  65. baTable.table.filter!.name = seachForm.name
  66. baTable.table.filter!.type = seachForm.type
  67. baTable.table.filter!.status = seachForm.status
  68. baTable.getIndex()
  69. }
  70. const baTable = new baTableClass(
  71. new baTableApi('/admin/pay.Config/'),
  72. {
  73. column: [
  74. {
  75. label: '编号',
  76. prop: 'id',
  77. align: 'center',
  78. width: 70,
  79. },
  80. {
  81. label: '配置名称',
  82. prop: 'name',
  83. align: 'center',
  84. minWidth: 160,
  85. },
  86. {
  87. label: '支付类型',
  88. prop: 'type',
  89. align: 'center',
  90. minWidth: 120,
  91. render: 'tag',
  92. custom: {
  93. '1': 'success',
  94. '2': '',
  95. },
  96. replaceValue: {
  97. '1': '微信支付',
  98. '2': '支付宝支付',
  99. },
  100. },
  101. {
  102. label: '应用ID/AppId',
  103. prop: 'app_id',
  104. align: 'center',
  105. minWidth: 180,
  106. },
  107. {
  108. label: '商户ID',
  109. prop: 'mch_id',
  110. align: 'center',
  111. minWidth: 120,
  112. },
  113. {
  114. label: '商户密钥/API密钥',
  115. prop: 'key',
  116. align: 'center',
  117. minWidth: 200,
  118. },
  119. {
  120. label: '支付通知地址',
  121. prop: 'notify_url',
  122. align: 'center',
  123. minWidth: 250,
  124. },
  125. {
  126. label: 'H5支付通知地址',
  127. prop: 'h5_notify_url',
  128. align: 'center',
  129. minWidth: 250,
  130. },
  131. {
  132. label: '支付宝公钥地址',
  133. prop: 'public_key_path',
  134. align: 'center',
  135. minWidth: 180,
  136. },
  137. {
  138. label: '支付宝私钥地址',
  139. prop: 'private_key_path',
  140. align: 'center',
  141. minWidth: 180,
  142. },
  143. {
  144. label: '状态',
  145. prop: 'status',
  146. align: 'center',
  147. render: 'tag',
  148. custom: {
  149. '0': 'danger',
  150. '1': 'success',
  151. },
  152. replaceValue: {
  153. '0': '禁用',
  154. '1': '启用',
  155. },
  156. minWidth: 100,
  157. },
  158. {
  159. label: '创建时间',
  160. prop: 'create_time',
  161. align: 'center',
  162. minWidth: 170,
  163. operator: false,
  164. },
  165. {
  166. label: '更新时间',
  167. prop: 'update_time',
  168. align: 'center',
  169. minWidth: 170,
  170. operator: false,
  171. },
  172. {
  173. label: '操作',
  174. align: 'center',
  175. width: '180',
  176. render: 'slot',
  177. slotName: 'operate',
  178. },
  179. ],
  180. dblClickNotEditColumn: [undefined,],
  181. filter: {
  182. limit: 20,
  183. },
  184. },
  185. {
  186. defaultItems: {
  187. id: null,
  188. name: '',
  189. type: '',
  190. status: '1',
  191. app_id: '',
  192. mch_id: '',
  193. key: '',
  194. notify_url: '',
  195. h5_notify_url: '',
  196. public_key_path: '',
  197. private_key_path: '',
  198. },
  199. },
  200. )
  201. baTable.mount()
  202. baTable.getIndex()
  203. provide('baTable', baTable)
  204. // 删除
  205. const handleDel = (row: TableRow) => {
  206. ElMessageBox.confirm(`确定删除配置"${row.name}"吗?`, '提示', {
  207. confirmButtonText: '确定',
  208. cancelButtonText: '取消',
  209. type: 'warning',
  210. }).then(() => {
  211. del({ id: row.id }).then(() => {
  212. baTable.getIndex()
  213. })
  214. })
  215. }
  216. const openForm = (type: 'Add' | 'Edit', row?: TableRow) => {
  217. if (type === 'Edit' && !row) return
  218. baTable.form.items = row ? cloneDeep(row) : cloneDeep(baTable.form.defaultItems)
  219. // 统一支付类型和状态为字符串,避免下拉框/单选框显示为“1”而不是对应中文
  220. if (baTable.form.items) {
  221. if (baTable.form.items.type !== undefined && baTable.form.items.type !== null) {
  222. baTable.form.items.type = String(baTable.form.items.type)
  223. }
  224. if (baTable.form.items.status !== undefined && baTable.form.items.status !== null) {
  225. baTable.form.items.status = String(baTable.form.items.status)
  226. }
  227. }
  228. baTable.form.operate = type
  229. baTable.form.operateIds = row && baTable.table.pk ? [row[baTable.table.pk]] : []
  230. }
  231. const onAdd = () => openForm('Add')
  232. const onEdit = (row: TableRow) => openForm('Edit', row)
  233. </script>
  234. <style scoped lang="scss">
  235. .el-form--inline .el-form-item {
  236. margin-right: 8px;
  237. }
  238. </style>