index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <template>
  2. <div class="table-demo">
  3. <bs-table v-bind="tableOptions">
  4. <template #searchRight>
  5. <a-space>
  6. <a-button type="primary" @click="goDetailPage">
  7. <template #icon>
  8. <PlusOutlined />
  9. </template>
  10. <span>新增</span>
  11. </a-button>
  12. </a-space>
  13. </template>
  14. </bs-table>
  15. </div>
  16. </template>
  17. <script setup lang="jsx">
  18. import BsTable, { useBsTable } from '/@/components/BsUi/Table/index.js';
  19. import { onMounted, ref, watch } from 'vue';
  20. import { useRouter } from 'vue-router';
  21. const props = defineProps({
  22. selectedRulesId: String,
  23. });
  24. const {
  25. tableOptions,
  26. fetchTableData,
  27. setTablePropsValue: setValue,
  28. getTablePropsValue: getValue,
  29. } = useBsTable({
  30. tableOptions: {
  31. url: '/supports/risk/rule/queryPage',
  32. gridOptions: {
  33. loading: false,
  34. columns: [
  35. {
  36. type: 'seq',
  37. width: 80,
  38. align: 'center',
  39. },
  40. {
  41. title: '风险维度',
  42. field: 'riskDimension',
  43. width: 85,
  44. ellipsis: true,
  45. formatter: ({ cellValue }) => {
  46. return cellValue && cellValue.length > 0 ? cellValue[0].valueName : '';
  47. },
  48. },
  49. {
  50. title: '风险模板',
  51. // field: 'riskModel',
  52. width: 85,
  53. ellipsis: true,
  54. slots: {
  55. default({ row, column }) {
  56. return <span>{row?.riskModel?.[0].valueName}</span>;
  57. },
  58. },
  59. },
  60. {
  61. title: '风险等级',
  62. field: 'riskLevel',
  63. width: 85,
  64. ellipsis: true,
  65. slots: {
  66. default({ row, column }) {
  67. return <span>{row?.riskLevel?.[0].valueName}</span>;
  68. },
  69. },
  70. },
  71. {
  72. title: '风险指标',
  73. field: 'riskMetrics',
  74. width: 110,
  75. ellipsis: true,
  76. },
  77. {
  78. title: '指标定义',
  79. field: 'definedMetrics',
  80. width: 100,
  81. ellipsis: true,
  82. },
  83. {
  84. title: '条件运算符',
  85. field: 'operator',
  86. width: 100,
  87. ellipsis: true,
  88. slots: {
  89. default({ row, column }) {
  90. return <span>{row?.operator?.[0].valueName}</span>;
  91. },
  92. },
  93. },
  94. {
  95. title: '条件控制值',
  96. field: 'conditionalValue',
  97. width: 100,
  98. ellipsis: true,
  99. },
  100. {
  101. title: '提醒方式',
  102. field: 'remindWay',
  103. width: 100,
  104. ellipsis: true,
  105. slots: {
  106. default({ row, column }) {
  107. return <span>{row?.remindWay?.[0].valueName}</span>;
  108. },
  109. },
  110. },
  111. {
  112. title: '提醒时间(每天)',
  113. field: 'remindTime',
  114. width: 120,
  115. ellipsis: true,
  116. },
  117. {
  118. title: '风险等级',
  119. field: 'riskGrade',
  120. width: 100,
  121. ellipsis: true,
  122. slots: {
  123. default({ row, column }) {
  124. return <span>{row?.riskGrade?.[0].valueName}</span>;
  125. },
  126. },
  127. },
  128. {
  129. title: '状态',
  130. field: 'enable',
  131. width: 100,
  132. ellipsis: true,
  133. // formatter: (cellValue) => {
  134. // return cellValue === 'true' ? '启用' : '禁用';
  135. // },
  136. slots: {
  137. default({ row, column }) {
  138. return <span>{row.enable === 'true' ? '启用' : '禁用'}</span>;
  139. },
  140. },
  141. },
  142. {
  143. field: 'opt',
  144. title: '操作',
  145. width: '120px',
  146. fixed: 'right',
  147. align: 'center',
  148. slots: {
  149. default({ row, column }) {
  150. return (
  151. <a-button
  152. type='text'
  153. size='small'
  154. onClick={() => {
  155. goDetailPage(row);
  156. }}
  157. >
  158. 编辑
  159. </a-button>
  160. );
  161. },
  162. },
  163. },
  164. ],
  165. data: [
  166. {
  167. id: 1,
  168. name: '测试数据',
  169. dictField: [
  170. {
  171. dictKeyId: '',
  172. dictValueId: '',
  173. remark: '',
  174. sort: 3,
  175. status: 1,
  176. valueCode: '03',
  177. valueName: '微信公众号',
  178. },
  179. ],
  180. },
  181. ], // 模拟数据源
  182. },
  183. searchConfig: {
  184. enabled: true,
  185. fieldSpan: 6,
  186. fields: [
  187. {
  188. field: 'name',
  189. label: '',
  190. component: 'a-input',
  191. componentProps: {
  192. placeholder: '请输入服务商名称',
  193. },
  194. },
  195. {
  196. field: 'name1',
  197. label: '',
  198. component: 'a-select',
  199. componentProps: {
  200. placeholder: '请选择地址',
  201. },
  202. },
  203. {
  204. field: 'name2',
  205. label: '',
  206. component: 'a-select',
  207. componentProps: {
  208. placeholder: '请选择服务商类型',
  209. },
  210. },
  211. ],
  212. },
  213. pagerConfig: {
  214. enabled: true,
  215. pageSize: 10,
  216. pageNum: 1,
  217. },
  218. toolbarConfig: {},
  219. tableSearchBeforeBiz() {
  220. const searchParams = getValue('searchConfig.data');
  221. setValue('searchConfig.data', { ...searchParams, key: props.selectedRulesId });
  222. },
  223. },
  224. });
  225. // 监听 selectedRulesId 的变化
  226. watch(
  227. () => props.selectedRulesId,
  228. (newVal, oldVal) => {
  229. if (newVal !== oldVal) {
  230. fetchTableData(newVal);
  231. }
  232. },
  233. { immediate: true }
  234. );
  235. onMounted(() => {
  236. console.log('表格已加载');
  237. });
  238. const router = useRouter();
  239. function goDetailPage(record) {
  240. console.log('record', record);
  241. router.push({
  242. path: '/business-rules/create-rules',
  243. query: {
  244. id: record.id,
  245. },
  246. });
  247. }
  248. </script>
  249. <style scoped lang="scss">
  250. .table-demo {
  251. }
  252. </style>