|
@@ -21,8 +21,8 @@
|
|
|
<el-button link type="primary" @click.prevent="toEdit(scope.row)" v-if="scope.row.type == 'table'">修改</el-button>
|
|
|
<el-button link type="success" @click.prevent="toAddDir(scope.row)" v-if="scope.row.type == 'dir'">添加下级文件夹</el-button>
|
|
|
<el-button link type="success" @click.prevent="toAddTab(scope.row)" v-if="scope.row.type == 'dir'">添加下级表</el-button>
|
|
|
- <el-button link type="warning">导出</el-button>
|
|
|
- <el-button link type="warning">导出ts</el-button>
|
|
|
+ <el-button link type="warning" @click.prevent="toExport(scope.row)" v-if="scope.row.type == 'table'">导出</el-button>
|
|
|
+ <el-button link type="warning" @click.prevent="toExportTs(scope.row)" v-if="scope.row.type == 'table'">导出ts</el-button>
|
|
|
<el-button link type="danger" @click.prevent="toDelDir(scope.row)" v-if="scope.row.type == 'dir'">删除</el-button>
|
|
|
<el-button link type="danger" @click.prevent="toDel(scope.row)" v-if="scope.row.type == 'table'">删除</el-button>
|
|
|
</template>
|
|
@@ -33,6 +33,7 @@
|
|
|
</template>
|
|
|
<script setup lang="ts">
|
|
|
import { ref } from 'vue';
|
|
|
+import _ from 'lodash';
|
|
|
import type { Ref } from 'vue';
|
|
|
import { useCounterStore as useStore } from '@/stores/counter';
|
|
|
import type { IQueryResult } from '@/util/types.util';
|
|
@@ -102,6 +103,48 @@ const toDelDir = (row: { _id: string }) => {
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
+// #region 导出
|
|
|
+function isValidKey(key: string | number | symbol, object: object): key is keyof typeof object {
|
|
|
+ return key in object;
|
|
|
+}
|
|
|
+// 导出
|
|
|
+const toExport = async (row: { _id: string }) => {
|
|
|
+ const res: IQueryResult = await store.exportData({ ids: row._id });
|
|
|
+ if (!_.isObject(res)) {
|
|
|
+ ElMessage({ type: 'warning', message: '获取的数据格式错误,无法导出' });
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ for (const key in res) {
|
|
|
+ let title = `${key}.js`;
|
|
|
+ if (isValidKey(key, res)) {
|
|
|
+ let blob = new Blob([res[key]]);
|
|
|
+ let a = document.createElement('a');
|
|
|
+ a.href = window.URL.createObjectURL(blob);
|
|
|
+ a.download = title;
|
|
|
+ a.click();
|
|
|
+ }
|
|
|
+ }
|
|
|
+};
|
|
|
+// 导出Ts
|
|
|
+const toExportTs = async (row: { _id: string }) => {
|
|
|
+ const res: IQueryResult = await store.exportTSData({ ids: row._id });
|
|
|
+ if (!_.isObject(res)) {
|
|
|
+ ElMessage({ type: 'warning', message: '获取的数据格式错误,无法导出' });
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ for (const key in res) {
|
|
|
+ let title = `${key}.js`;
|
|
|
+
|
|
|
+ if (isValidKey(key, res)) {
|
|
|
+ let blob = new Blob([res[key]]);
|
|
|
+ let a = document.createElement('a');
|
|
|
+ a.href = window.URL.createObjectURL(blob);
|
|
|
+ a.download = title;
|
|
|
+ a.click();
|
|
|
+ }
|
|
|
+ }
|
|
|
+};
|
|
|
+// #endregion
|
|
|
</script>
|
|
|
|
|
|
<style scoped>
|