channel.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <cl-crud ref="Crud">
  3. <cl-row>
  4. <!-- 刷新按钮 -->
  5. <cl-refresh-btn />
  6. <!-- 新增按钮 -->
  7. <cl-add-btn />
  8. <!-- 删除按钮 -->
  9. <cl-multi-delete-btn />
  10. <cl-flex1 />
  11. <!-- 关键字搜索 -->
  12. <cl-search-key placeholder="搜索关键字" />
  13. </cl-row>
  14. <cl-row>
  15. <!-- 数据表格 -->
  16. <cl-table ref="Table"> </cl-table>
  17. </cl-row>
  18. <cl-row>
  19. <cl-flex1 />
  20. <!-- 分页控件 -->
  21. <cl-pagination />
  22. </cl-row>
  23. <!-- 新增、编辑 -->
  24. <cl-upsert ref="Upsert" />
  25. </cl-crud>
  26. </template>
  27. <script lang="ts" name="payment-channel" setup>
  28. import { useCrud, useTable, useUpsert } from '@cool-vue/crud';
  29. import { useCool } from '/@/cool';
  30. import { ref } from 'vue';
  31. const { service } = useCool();
  32. const currencyList = ref<any[]>([]);
  33. // cl-upsert
  34. const Upsert = useUpsert({
  35. items: [
  36. {
  37. label: '渠道名称',
  38. prop: 'name',
  39. component: { name: 'el-input', props: { clearable: true } },
  40. required: true
  41. },
  42. {
  43. label: '渠道代码',
  44. prop: 'code',
  45. component: { name: 'el-input', props: { clearable: true } },
  46. required: true
  47. },
  48. {
  49. label: '渠道描述',
  50. prop: 'description',
  51. component: { name: 'el-input', props: { type: 'textarea', rows: 4 } }
  52. },
  53. {
  54. label: 'key',
  55. prop: 'apiKey',
  56. component: { name: 'el-input', props: { clearable: true } }
  57. },
  58. {
  59. label: 'secret',
  60. prop: 'apiSecret',
  61. component: { name: 'el-input', props: { clearable: true } }
  62. },
  63. {
  64. label: 'url',
  65. prop: 'apiUrl',
  66. component: { name: 'el-input', props: { clearable: true } }
  67. },
  68. {
  69. label: '是否启用',
  70. prop: 'isEnabled',
  71. flex: false,
  72. component: { name: 'cl-switch' },
  73. required: true
  74. },
  75. {
  76. label: '支持的货币',
  77. prop: 'supportedCurrencies',
  78. hook: {
  79. bind: ['split', 'number']
  80. },
  81. component: {
  82. name: 'el-select',
  83. props: { multiple: true, options: currencyList }
  84. },
  85. required: true
  86. }
  87. ],
  88. async onOpen() {
  89. const currencyList = await service.payment.currency.list();
  90. Upsert.value?.setOptions(
  91. 'supportedCurrencies',
  92. currencyList.map(v => ({ label: v.name, value: v.id }))
  93. );
  94. // Upsert.value?.setForm(
  95. // 'supportedCurrencies',
  96. // data && data.length > 0 ? data.currencies.split(',') : []
  97. // );
  98. }
  99. });
  100. // cl-table
  101. const Table = useTable({
  102. columns: [
  103. { type: 'selection' },
  104. { label: '渠道名称', prop: 'name' },
  105. { label: '渠道代码', prop: 'code' },
  106. { label: '渠道描述', prop: 'description', showOverflowTooltip: true },
  107. { label: '是否启用', prop: 'isEnabled', component: { name: 'cl-switch' } },
  108. { type: 'op', buttons: ['edit', 'delete'] }
  109. ]
  110. });
  111. // cl-crud
  112. const Crud = useCrud(
  113. {
  114. service: service.payment.channel
  115. },
  116. app => {
  117. app.refresh();
  118. }
  119. );
  120. // 刷新
  121. function refresh(params?: any) {
  122. Crud.value?.refresh(params);
  123. }
  124. </script>