index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. <template>
  2. <!-- 搜索 -->
  3. <ContentWrap>
  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 label="开启状态" prop="status">
  21. <el-select
  22. v-model="queryParams.status"
  23. placeholder="请选择开启状态"
  24. clearable
  25. class="!w-240px"
  26. >
  27. <el-option
  28. v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
  29. :key="dict.value"
  30. :label="dict.label"
  31. :value="dict.value"
  32. />
  33. </el-select>
  34. </el-form-item>
  35. <el-form-item label="创建时间" prop="createTime">
  36. <el-date-picker
  37. v-model="queryParams.createTime"
  38. value-format="YYYY-MM-DD HH:mm:ss"
  39. type="daterange"
  40. start-placeholder="开始日期"
  41. end-placeholder="结束日期"
  42. :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
  43. class="!w-240px"
  44. />
  45. </el-form-item>
  46. <el-form-item>
  47. <el-button @click="handleQuery"> <Icon icon="ep:search" class="mr-5px" />搜索 </el-button>
  48. <el-button @click="resetQuery"> <Icon icon="ep:refresh" class="mr-5px" />重置 </el-button>
  49. <el-button
  50. type="primary"
  51. plain
  52. @click="openForm('create')"
  53. v-hasPermi="['system:tenant:create']"
  54. >
  55. <Icon icon="ep:plus" class="mr-5px" /> 新增
  56. </el-button>
  57. <el-button
  58. type="success"
  59. plain
  60. @click="handleExport"
  61. :loading="exportLoading"
  62. v-hasPermi="['system:tenant:export']"
  63. >
  64. <Icon icon="ep:download" class="mr-5px" /> 导出
  65. </el-button>
  66. </el-form-item>
  67. </el-form>
  68. </ContentWrap>
  69. <!-- 列表 -->
  70. <ContentWrap>
  71. <el-table v-loading="loading" :data="list">
  72. <el-table-column label="应用编号" align="center" prop="id" />
  73. <el-table-column label="应用名" align="center" prop="name" />
  74. <el-table-column label="开启状态" align="center" prop="status">
  75. <template #default="scope">
  76. <el-switch
  77. v-model="scope.row.status"
  78. :active-value="0"
  79. :inactive-value="1"
  80. @change="handleStatusChange(scope.row)"
  81. />
  82. </template>
  83. </el-table-column>
  84. <el-table-column label="支付宝配置" align="center">
  85. <el-table-column :label="PayChannelEnum.ALIPAY_APP.name" align="center">
  86. <template #default="scope">
  87. <el-button
  88. type="success"
  89. v-if="isChannelExists(scope.row.channelCodes, PayChannelEnum.ALIPAY_APP.code)"
  90. @click="openChannelForm(scope.row, PayChannelEnum.ALIPAY_APP.code, PayType.ALIPAY)"
  91. circle
  92. >
  93. <Icon icon="ep:check" />
  94. </el-button>
  95. <el-button
  96. v-else
  97. type="danger"
  98. circle
  99. @click="openChannelForm(scope.row, PayChannelEnum.ALIPAY_APP.code, PayType.ALIPAY)"
  100. >
  101. <Icon icon="ep:close" />
  102. </el-button>
  103. </template>
  104. </el-table-column>
  105. <el-table-column :label="PayChannelEnum.ALIPAY_PC.name" align="center">
  106. <template #default="scope">
  107. <el-button
  108. type="success"
  109. circle
  110. v-if="isChannelExists(scope.row.channelCodes, PayChannelEnum.ALIPAY_PC.code)"
  111. @click="openChannelForm(scope.row, PayChannelEnum.ALIPAY_PC.code, PayType.ALIPAY)"
  112. >
  113. <Icon icon="ep:check" />
  114. </el-button>
  115. <el-button
  116. v-else
  117. type="danger"
  118. circle
  119. @click="openChannelForm(scope.row, PayChannelEnum.ALIPAY_PC.code, PayType.ALIPAY)"
  120. >
  121. <Icon icon="ep:close" />
  122. </el-button>
  123. </template>
  124. </el-table-column>
  125. <el-table-column :label="PayChannelEnum.ALIPAY_WAP.name" align="center">
  126. <template #default="scope">
  127. <el-button
  128. type="success"
  129. circle
  130. v-if="isChannelExists(scope.row.channelCodes, PayChannelEnum.ALIPAY_WAP.code)"
  131. @click="openChannelForm(scope.row, PayChannelEnum.ALIPAY_WAP.code, PayType.ALIPAY)"
  132. >
  133. <Icon icon="ep:check" />
  134. </el-button>
  135. <el-button
  136. v-else
  137. type="danger"
  138. circle
  139. @click="openChannelForm(scope.row, PayChannelEnum.ALIPAY_WAP.code, PayType.ALIPAY)"
  140. >
  141. <Icon icon="ep:close" />
  142. </el-button>
  143. </template>
  144. </el-table-column>
  145. <el-table-column :label="PayChannelEnum.ALIPAY_QR.name" align="center">
  146. <template #default="scope">
  147. <el-button
  148. type="success"
  149. circle
  150. v-if="isChannelExists(scope.row.channelCodes, PayChannelEnum.ALIPAY_QR.code)"
  151. @click="openChannelForm(scope.row, PayChannelEnum.ALIPAY_QR.code, PayType.ALIPAY)"
  152. >
  153. <Icon icon="ep:check" />
  154. </el-button>
  155. <el-button
  156. v-else
  157. type="danger"
  158. circle
  159. @click="openChannelForm(scope.row, PayChannelEnum.ALIPAY_QR.code, PayType.ALIPAY)"
  160. >
  161. <Icon icon="ep:close" />
  162. </el-button>
  163. </template>
  164. </el-table-column>
  165. <el-table-column :label="PayChannelEnum.ALIPAY_BAR.name" align="center">
  166. <template #default="scope">
  167. <el-button
  168. type="success"
  169. circle
  170. v-if="isChannelExists(scope.row.channelCodes, PayChannelEnum.ALIPAY_BAR.code)"
  171. @click="openChannelForm(scope.row, PayChannelEnum.ALIPAY_BAR.code, PayType.ALIPAY)"
  172. >
  173. <Icon icon="ep:check" />
  174. </el-button>
  175. <el-button
  176. v-else
  177. type="danger"
  178. circle
  179. @click="openChannelForm(scope.row, PayChannelEnum.ALIPAY_BAR.code, PayType.ALIPAY)"
  180. >
  181. <Icon icon="ep:close" />
  182. </el-button>
  183. </template>
  184. </el-table-column>
  185. </el-table-column>
  186. <el-table-column label="微信配置" align="center">
  187. <el-table-column :label="PayChannelEnum.WX_LITE.name" align="center">
  188. <template #default="scope">
  189. <el-button
  190. type="success"
  191. circle
  192. v-if="isChannelExists(scope.row.channelCodes, PayChannelEnum.WX_LITE.code)"
  193. @click="openChannelForm(scope.row, PayChannelEnum.WX_LITE.code, PayType.WECHAT)"
  194. >
  195. <Icon icon="ep:check" />
  196. </el-button>
  197. <el-button
  198. v-else
  199. type="danger"
  200. circle
  201. @click="openChannelForm(scope.row, PayChannelEnum.WX_LITE.code, PayType.WECHAT)"
  202. >
  203. <Icon icon="ep:close" />
  204. </el-button>
  205. </template>
  206. </el-table-column>
  207. <el-table-column :label="PayChannelEnum.WX_PUB.name" align="center">
  208. <template #default="scope">
  209. <el-button
  210. type="success"
  211. circle
  212. v-if="isChannelExists(scope.row.channelCodes, PayChannelEnum.WX_PUB.code)"
  213. @click="openChannelForm(scope.row, PayChannelEnum.WX_PUB.code, PayType.WECHAT)"
  214. >
  215. <Icon icon="ep:check" />
  216. </el-button>
  217. <el-button
  218. v-else
  219. type="danger"
  220. circle
  221. @click="openChannelForm(scope.row, PayChannelEnum.WX_PUB.code, PayType.WECHAT)"
  222. >
  223. <Icon icon="ep:close" />
  224. </el-button>
  225. </template>
  226. </el-table-column>
  227. <el-table-column :label="PayChannelEnum.WX_APP.name" align="center">
  228. <template #default="scope">
  229. <el-button
  230. type="success"
  231. circle
  232. v-if="isChannelExists(scope.row.channelCodes, PayChannelEnum.WX_APP.code)"
  233. @click="openChannelForm(scope.row, PayChannelEnum.WX_APP.code, PayType.WECHAT)"
  234. >
  235. <Icon icon="ep:check" />
  236. </el-button>
  237. <el-button
  238. v-else
  239. type="danger"
  240. circle
  241. @click="openChannelForm(scope.row, PayChannelEnum.WX_APP.code, PayType.WECHAT)"
  242. >
  243. <Icon icon="ep:close" />
  244. </el-button>
  245. </template>
  246. </el-table-column>
  247. </el-table-column>
  248. <el-table-column label="模拟支付配置" align="center">
  249. <el-table-column :label="PayChannelEnum.MOCK.name" align="center">
  250. <template #default="scope">
  251. <el-button
  252. type="success"
  253. circle
  254. v-if="isChannelExists(scope.row.channelCodes, PayChannelEnum.MOCK.code)"
  255. @click="openChannelForm(scope.row, PayChannelEnum.MOCK.code)"
  256. ><Icon icon="ep:check"
  257. /></el-button>
  258. <el-button
  259. v-else
  260. type="danger"
  261. circle
  262. @click="openChannelForm(scope.row, PayChannelEnum.MOCK.code)"
  263. ><Icon icon="ep:close"
  264. /></el-button>
  265. </template>
  266. </el-table-column>
  267. </el-table-column>
  268. <el-table-column label="操作" align="center" min-width="110" fixed="right">
  269. <template #default="scope">
  270. <el-button
  271. link
  272. type="primary"
  273. @click="openForm('update', scope.row.id)"
  274. v-hasPermi="['system:tenant:update']"
  275. >
  276. 编辑
  277. </el-button>
  278. <el-button
  279. link
  280. type="danger"
  281. @click="handleDelete(scope.row.id)"
  282. v-hasPermi="['system:tenant:delete']"
  283. >
  284. 删除
  285. </el-button>
  286. </template>
  287. </el-table-column>
  288. </el-table>
  289. <!-- 分页 -->
  290. <Pagination
  291. :total="total"
  292. v-model:page="queryParams.pageNo"
  293. v-model:limit="queryParams.pageSize"
  294. @pagination="getList"
  295. />
  296. </ContentWrap>
  297. <!-- 表单弹窗:添加/修改 -->
  298. <AppForm ref="formRef" @success="getList" />
  299. <AlipayChannelForm ref="alipayFormRef" @success="getList" />
  300. <WeixinChannelForm ref="weixinFormRef" @success="getList" />
  301. <MockChannelForm ref="mockFormRef" @success="getList" />
  302. </template>
  303. <script lang="ts" setup>
  304. import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  305. import download from '@/utils/download'
  306. import * as PayappApi from '@/api/pay/app'
  307. import AppForm from './components/AppForm.vue'
  308. import { PayChannelEnum, PayType } from '@/utils/constants'
  309. import AlipayChannelForm from './components/channel/AlipayChannelForm.vue'
  310. import WeixinChannelForm from './components/weixinChannelForm.vue'
  311. import MockChannelForm from './components/mockChannelForm.vue'
  312. import { CommonStatusEnum } from '@/utils/constants'
  313. defineOptions({ name: 'PayApp' })
  314. const message = useMessage() // 消息弹窗
  315. const { t } = useI18n() // 国际化
  316. const alipayFormRef = ref()
  317. const weixinFormRef = ref()
  318. const mockFormRef = ref()
  319. const loading = ref(true) // 列表的加载中
  320. const total = ref(0) // 列表的总页数
  321. const list = ref([]) // 列表的数据
  322. const queryParams = reactive({
  323. pageNo: 1,
  324. pageSize: 10,
  325. name: undefined,
  326. status: undefined,
  327. remark: undefined,
  328. payNotifyUrl: undefined,
  329. refundNotifyUrl: undefined,
  330. merchantName: undefined,
  331. createTime: []
  332. })
  333. const queryFormRef = ref() // 搜索的表单
  334. const exportLoading = ref(false) // 导出的加载中
  335. /** 查询列表 */
  336. const getList = async () => {
  337. loading.value = true
  338. try {
  339. const data = await PayappApi.getAppPage(queryParams)
  340. list.value = data.list
  341. total.value = data.total
  342. } finally {
  343. loading.value = false
  344. }
  345. }
  346. /** 搜索按钮操作 */
  347. const handleQuery = () => {
  348. queryParams.pageNo = 1
  349. getList()
  350. }
  351. /** 重置按钮操作 */
  352. const resetQuery = () => {
  353. queryFormRef.value.resetFields()
  354. handleQuery()
  355. }
  356. /** 应用状态修改 */
  357. const handleStatusChange = async (row: any) => {
  358. let text = row.status === CommonStatusEnum.ENABLE ? '启用' : '停用'
  359. try {
  360. await message.confirm('确认要"' + text + '""' + row.name + '"应用吗?')
  361. await PayappApi.changeAppStatus({ id: row.id, status: row.status })
  362. message.success(text + '成功')
  363. } catch {
  364. row.status =
  365. row.status === CommonStatusEnum.ENABLE ? CommonStatusEnum.DISABLE : CommonStatusEnum.ENABLE
  366. }
  367. }
  368. /** 添加/修改操作 */
  369. const channelParam = reactive({
  370. loading: false,
  371. appId: null, // 应用 ID
  372. payCode: null // 渠道编码
  373. })
  374. const formRef = ref()
  375. const openForm = (type: string, id?: number) => {
  376. formRef.value.open(type, id)
  377. }
  378. /** 删除按钮操作 */
  379. const handleDelete = async (id: number) => {
  380. try {
  381. // 删除的二次确认
  382. await message.delConfirm()
  383. // 发起删除
  384. await PayappApi.deleteApp(id)
  385. message.success(t('common.delSuccess'))
  386. // 刷新列表
  387. await getList()
  388. } catch {}
  389. }
  390. /** 导出按钮操作 */
  391. const handleExport = async () => {
  392. try {
  393. // 导出的二次确认
  394. await message.exportConfirm()
  395. // 发起导出
  396. exportLoading.value = true
  397. const data = await PayappApi.exportApp(queryParams)
  398. download.excel(data, '支付应用信息.xls')
  399. } finally {
  400. exportLoading.value = false
  401. }
  402. }
  403. /**
  404. * 根据渠道编码判断渠道列表中是否存在
  405. *
  406. * @param channels 渠道列表
  407. * @param channelCode 渠道编码
  408. */
  409. const isChannelExists = (channels, channelCode) => {
  410. if (!channels) {
  411. return false
  412. }
  413. return channels.indexOf(channelCode) !== -1
  414. }
  415. /**
  416. * 新增支付渠道信息
  417. */
  418. const openChannelForm = async (row, payCode, type) => {
  419. channelParam.loading = false
  420. channelParam.appId = row.id
  421. channelParam.payCode = payCode
  422. switch (type) {
  423. case PayType.ALIPAY:
  424. alipayFormRef.value.open(row.id, payCode)
  425. break
  426. case PayType.WECHAT:
  427. weixinFormRef.value.open(row.id, payCode)
  428. break
  429. case PayType.MOCK:
  430. mockFormRef.value.open(row.id, payCode)
  431. break
  432. }
  433. }
  434. /** 初始化 **/
  435. onMounted(async () => {
  436. await getList()
  437. })
  438. </script>