| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- import { h, ref } from 'vue';
- import { Button } from 'ant-design-vue';
- /**
- * Skill 约定记录(防止接口参数回归错误)
- * 1) skill 仅用于前端组件能力标记(如按钮 `:skill="true"`),不是后端接口业务字段。
- * 2) 通信/交易底层接口中的日期入参(startDate、endDate)统一使用 `YYYY-MM-DD`。
- * 3) 月维度字段映射为日期时:开始取当月第一天,结束取当月最后一天。
- */
- export function useTableSkill() {
- const queryLoading = ref(false);
- const runWithQueryLoading = async <T>(task: () => Promise<T>, timeoutMs = 15000): Promise<T> => {
- queryLoading.value = true;
- const stopLoadingTimer = window.setTimeout(() => {
- queryLoading.value = false;
- }, timeoutMs);
- try {
- return await task();
- } finally {
- window.clearTimeout(stopLoadingTimer);
- queryLoading.value = false;
- }
- };
- return {
- queryLoading,
- runWithQueryLoading,
- };
- }
- export function buildTableActionColumn<T = any>(
- onClick: (record: T) => void,
- options?: {
- title?: string;
- buttonText?: string;
- width?: number;
- },
- ) {
- return {
- title: options?.title || '操作',
- dataIndex: 'action',
- key: 'action',
- width: options?.width || 120,
- customRender: ({ record }: { record: T }) =>
- h(
- Button,
- {
- type: 'link',
- size: 'small',
- color: 'primary',
- skill: true,
- onClick: () => onClick(record),
- },
- { default: () => options?.buttonText || '查看详情' },
- ),
- };
- }
|