ChannelManage.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <div class="channel-manage" v-loading="loading">
  3. <el-table height="100%" class="sa-table" :data="tableData" stripe>
  4. <template #empty>
  5. <sa-empty />
  6. </template>
  7. <el-table-column prop="channelName" :label="t('modules.payment.channelName')" min-width="150"> </el-table-column>
  8. <el-table-column prop="merchantNum" :label="t('modules.payment.merchantId')" min-width="150"> </el-table-column>
  9. <el-table-column prop="appid" label="APPID" min-width="200"> </el-table-column>
  10. <el-table-column prop="secretKey" :label="t('modules.payment.secretKey')" min-width="300">
  11. <template #default="scope">
  12. <span class="secret-key">{{ scope.row.secretKey }}</span>
  13. </template>
  14. </el-table-column>
  15. <el-table-column :label="t('common.actions')" min-width="150" fixed="right">
  16. <template #default="scope">
  17. <el-button class="is-link" type="primary" @click="editChannel(scope.row)">
  18. {{ t('common.edit') }}
  19. </el-button>
  20. <el-popconfirm width="fit-content" :confirm-button-text="t('common.confirm')"
  21. :cancel-button-text="t('common.cancel')" :title="t('modules.payment.confirmDeleteChannel')"
  22. @confirm="deleteChannel(scope.row.id)">
  23. <template #reference>
  24. <el-button class="is-link" type="danger">{{ t('common.delete') }}</el-button>
  25. </template>
  26. </el-popconfirm>
  27. </template>
  28. </el-table-column>
  29. <el-table-column prop="notifyUrl" label="异步通知地址" min-width="200">
  30. <template #default="{ row }">
  31. <span class="notify-url">{{ row.notifyUrl || '--' }}</span>
  32. </template>
  33. </el-table-column>
  34. </el-table>
  35. </div>
  36. </template>
  37. <script setup>
  38. import { onMounted, ref } from 'vue';
  39. import { ElMessage } from 'element-plus';
  40. import { useI18n } from 'vue-i18n';
  41. import { useModal } from '@/sheep/hooks';
  42. import api from '../../../api';
  43. import ChannelEdit from '../edit.vue';
  44. const { t } = useI18n();
  45. const loading = ref(false);
  46. const tableData = ref([]);
  47. // 获取支付通道数据
  48. async function getData() {
  49. loading.value = true;
  50. try {
  51. const { code, data } = await api.payment.channel.list({});
  52. if (code == 200) {
  53. tableData.value = data || [];
  54. }
  55. } catch (error) {
  56. console.error('获取支付通道失败:', error);
  57. ElMessage.error(t('message.fetchDataFailed'));
  58. } finally {
  59. loading.value = false;
  60. }
  61. }
  62. // 编辑通道
  63. function editChannel(channel) {
  64. useModal(
  65. ChannelEdit,
  66. {
  67. title: t('modules.payment.editPaymentChannel'),
  68. type: 'edit',
  69. id: channel.id,
  70. data: channel,
  71. },
  72. {
  73. confirm: () => {
  74. getData();
  75. },
  76. },
  77. );
  78. }
  79. // 删除通道
  80. async function deleteChannel(id) {
  81. try {
  82. const { code } = await api.payment.channel.delete(id);
  83. if (code == 200) {
  84. ElMessage.success(t('message.deleteSuccess'));
  85. getData();
  86. }
  87. } catch (error) {
  88. console.error('删除支付通道失败:', error);
  89. ElMessage.error(t('message.deleteFailed'));
  90. }
  91. }
  92. // 暴露方法给父组件调用
  93. defineExpose({
  94. getData,
  95. });
  96. onMounted(() => {
  97. getData();
  98. });
  99. </script>
  100. <style lang="scss" scoped>
  101. .channel-manage {
  102. height: 100%;
  103. display: flex;
  104. flex-direction: column;
  105. .sa-table-wrap {
  106. flex: 1;
  107. margin-top: 16px;
  108. }
  109. }
  110. </style>