-
-
-
+ :active="active.index.toString()"
+ :tabs="tabs"
+ :search-fields="searchFields"
+ :query-params="queryParams"
+ :columns-fields="columnFields"
+ :rows="rows"
+ :current-page="queryParams.pageNum"
+ :page-size="queryParams.pageSize"
+ :total="queryParams.total"
+ :loading="loading"
+ @query="handleQuery"
+ @reset="handleReset"
+ @toggle="getRows"
+ />
@@ -22,101 +27,65 @@ export default {
name: 'App',
data() {
return {
- addTabDialogVisible: false,
- table: {
- form: [
- {
- type: 'input',
- label: '表名',
- prop: 'tableName',
- placeholder: '请输入表名',
- },
- {
- type: 'input',
- label: '表描述',
- prop: 'tableDescription',
- placeholder: '请输入表描述',
- span: 6
- },
- {
- type: 'input',
- label: '表注',
- prop: 'tableNote',
- placeholder: '请输入表注',
- },
- {
- type: 'select',
- label: '是否启用',
- prop: 'enable',
- placeholder: '请选择是否启用',
- options: [
- {
- label: '是',
- value: '1',
- default: true
- },
- {
- label: '否',
- value: '0'
- }
- ]
- },
- ],
- column: [
- {
- type: 'id',
- width: 55,
- align: 'center'
- },
- {
- title: '表名称',
- key: 'tableName',
- align: 'center'
- },
- {
- title: '描述',
- key: 'tableDescription',
- align: 'center'
- },
- {
- title: '表注',
- key: 'tableNote',
- align: 'center'
- },
- {
- title: '启用',
- key: 'enable',
- align: 'center',
- },
- {
- title: 'cron (定时)',
- key: 'cron',
- align: 'center'
- }
- ],
- rows: [],
- },
- initActiveTab: "0",
-
- tabs: [],
- activeTab: {
- title: undefined,
- name: undefined,
- dbType: undefined,
- url: undefined,
- username: undefined,
- driverClassName: undefined,
+ active: {
+ index: 0, // 默认值为 0,确保在 tabs 为空时不会出错
},
+ rows: [],
+ addTabDialogVisible: false,
+ searchFields: [
+ {
+ type: 'input',
+ label: '表名称',
+ prop: 'tableName',
+ placeholder: '请输入表名称',
+ gutter: 2,
+ },
+ {
+ type: 'input',
+ label: '表描述',
+ prop: 'tableDescription',
+ placeholder: '请输入表描述',
+ gutter: 2,
+ },
+ {
+ type: 'input',
+ label: '表注',
+ prop: 'tableNote',
+ placeholder: '请输入表注',
+ gutter: 2,
+ },
+ {
+ type: 'select',
+ label: '启用',
+ prop: 'enable',
+ placeholder: '请选择',
+ gutter: 2,
+ options: [
+ {label: '是', value: '1'},
+ {label: '否', value: '0'},
+ ],
+ },
+ ],
queryParams: {
pageNum: 1,
pageSize: 10,
+ total: 0,
name: undefined,
tableName: undefined,
enable: undefined,
tableDescription: undefined,
tableNote: undefined,
cron: undefined,
- }
+ },
+ columnFields: [
+ {label: 'ID', prop: 'id', width: '100', sortable: true},
+ {label: '表名称', prop: 'tableName', sortable: true},
+ {label: '表注', prop: 'tableDescription', sortable: true},
+ {label: '启用', prop: 'enable', formatter: (value) => (value ? '启用' : '禁用'), sortable: true},
+ {label: '定时', prop: 'cron'},
+ ],
+ tabs: [],
+ loading: false, // 添加 loading 属性
};
},
@@ -126,45 +95,60 @@ export default {
methods: {
getNav() {
- getNav().then(response => {
- this.tabs = response.data.map(item => ({
- title: item.alias,
- name: item.name,
- dbType: item.dbType,
- url: item.url,
- username: item.username,
- driverClassName: item.driverClassName
- }));
- if (this.tabs.length > 0) {
- this.activeTab = this.tabs[0];
- this.queryParams.name = this.activeTab.name
- this.getDataList();
- }
- }).catch(error => {
- console.error('Failed to fetch navigation data:', error);
- });
+ getNav()
+ .then(response => {
+ this.tabs = response.data.map(item => ({
+ title: item.alias,
+ name: item.name,
+ dbType: item.dbType,
+ url: item.url,
+ username: item.username,
+ driverClassName: item.driverClassName
+ }));
+ if (this.tabs.length > 0) {
+ this.active.index = 0; // 设置默认选中第一个标签页
+ this.queryParams.name = this.tabs[this.active.index].name;
+ this.getRows();
+ }
+ })
+ .catch(error => {
+ console.error('Failed to fetch navigation data:', error);
+ });
},
-
- backSelect(callBackActiveTab) {
- console.log(JSON.stringify(callBackActiveTab));
- this.activeTab = callBackActiveTab.activeTab
- this.queryParams.pageNum = callBackActiveTab.pageNum
- this.queryParams.pageSize = callBackActiveTab.pageSize
- this.queryParams.enable = callBackActiveTab.enable
- this.queryParams.name = this.activeTab.name
- this.getDataList();
+ // 查询
+ handleQuery() {
+ this.getRows();
},
-
- getDataList() {
- console.log('getDataList', JSON.stringify(this.queryParams));
+ // 重置
+ handleReset() {
+ this.queryParams = {
+ pageNum: 1,
+ pageSize: 10,
+ total: 0,
+ name: undefined,
+ tableName: undefined,
+ enable: undefined,
+ tableDescription: undefined,
+ tableNote: undefined,
+ cron: undefined,
+ };
+ this.getRows();
+ },
+ // 切换
+ getRows() {
+ this.loading = true; // 开始加载时设置 loading 为 true
getTasks(this.queryParams)
.then(response => {
- this.$refs.tabComponent.loadTableData(response.rows, response.total);
+ this.rows = response.rows;
+ this.queryParams.total = response.total; // 更新总记录数
})
.catch(error => {
console.error('Failed to fetch data list:', error);
+ })
+ .finally(() => {
+ this.loading = false; // 加载完成后设置 loading 为 false
});
- }
+ },
}
};