Browse Source

导出,移动

YY 2 years ago
parent
commit
a2c551edcd
3 changed files with 88 additions and 7 deletions
  1. 18 0
      src/stores/counter.ts
  2. 25 5
      src/views/parts/form-1.vue
  3. 45 2
      src/views/parts/table-1.vue

+ 18 - 0
src/stores/counter.ts

@@ -20,6 +20,7 @@ export const useCounterStore = defineStore('counter', () => {
   function increment() {
   function increment() {
     count.value++;
     count.value++;
   }
   }
+  // #region project
   const projectQuery = async ({ skip = 0, limit = undefined, ...info }: IQueryParams = {}): Promise<IQueryResult> => {
   const projectQuery = async ({ skip = 0, limit = undefined, ...info }: IQueryParams = {}): Promise<IQueryResult> => {
     let cond: IQueryType = {};
     let cond: IQueryType = {};
     if (skip) cond.skip = skip;
     if (skip) cond.skip = skip;
@@ -45,6 +46,8 @@ export const useCounterStore = defineStore('counter', () => {
     const res = await axios.$delete(`${projectApi.url}/${payload}`);
     const res = await axios.$delete(`${projectApi.url}/${payload}`);
     return res;
     return res;
   };
   };
+  // #endregion
+  // #region dir
   const dirQuery = async ({ skip = 0, limit = undefined, ...info }: IQueryParams = {}): Promise<IQueryResult> => {
   const dirQuery = async ({ skip = 0, limit = undefined, ...info }: IQueryParams = {}): Promise<IQueryResult> => {
     let cond: IQueryType = {};
     let cond: IQueryType = {};
     if (skip) cond.skip = skip;
     if (skip) cond.skip = skip;
@@ -70,6 +73,8 @@ export const useCounterStore = defineStore('counter', () => {
     const res = await axios.$delete(`${dirApi.url}/${payload}`);
     const res = await axios.$delete(`${dirApi.url}/${payload}`);
     return res;
     return res;
   };
   };
+  // #endregion
+  // #region table
   const tableQuery = async ({ skip = 0, limit = undefined, ...info }: IQueryParams = {}): Promise<IQueryResult> => {
   const tableQuery = async ({ skip = 0, limit = undefined, ...info }: IQueryParams = {}): Promise<IQueryResult> => {
     let cond: IQueryType = {};
     let cond: IQueryType = {};
     if (skip) cond.skip = skip;
     if (skip) cond.skip = skip;
@@ -95,6 +100,17 @@ export const useCounterStore = defineStore('counter', () => {
     const res = await axios.$delete(`${tableApi.url}/${payload}`);
     const res = await axios.$delete(`${tableApi.url}/${payload}`);
     return res;
     return res;
   };
   };
+  // 导出
+  const exportData = async (data: any): Promise<IQueryResult> => {
+    const res = await axios.$post(`${tableApi.url}/export`, data);
+    return res.data;
+  };
+  // 导出ts
+  const exportTSData = async (data: any): Promise<IQueryResult> => {
+    const res = await axios.$post(`${tableApi.url}/exportTS`, data);
+    return res.data;
+  };
+  // #endregion
 
 
   return {
   return {
     count,
     count,
@@ -110,6 +126,8 @@ export const useCounterStore = defineStore('counter', () => {
     tableCreate,
     tableCreate,
     tableUpdate,
     tableUpdate,
     tableDelete,
     tableDelete,
+    exportData,
+    exportTSData,
     dirQuery,
     dirQuery,
     dirFetch,
     dirFetch,
     dirCreate,
     dirCreate,

+ 25 - 5
src/views/parts/form-1.vue

@@ -72,10 +72,18 @@
             </template>
             </template>
           </el-table-column>
           </el-table-column>
           <el-table-column label="操作" align="center" width="175">
           <el-table-column label="操作" align="center" width="175">
-            <template #default="{ row }">
-              <el-button text type="danger" @click="toDel(row)">删除</el-button>
-              <!-- <el-button text type="primary" @click="toDel(row)">向下</el-button>
-              <el-button text type="success" @click="toDel(row)">向上</el-button> -->
+            <template #default="{ row, $index }">
+              <el-col :span="24" class="propbtn">
+                <el-col :span="8">
+                  <el-button v-if="$index > 0" text type="primary" @click="toUp('up', $index, row)">向上</el-button>
+                </el-col>
+                <el-col :span="8">
+                  <el-button v-if="$index < form.columns.length - 1" text type="success" @click="toUp('down', $index, row)">向下</el-button>
+                </el-col>
+                <el-col :span="8">
+                  <el-button text type="danger" @click="toDel(row)">删除</el-button>
+                </el-col>
+              </el-col>
             </template>
             </template>
           </el-table-column>
           </el-table-column>
         </el-table>
         </el-table>
@@ -125,7 +133,10 @@ let form: Ref<{ columns: any; name_zh: string; remark: string; name: string; pro
   project: '',
   project: '',
   dir: '',
   dir: '',
 });
 });
+
 form.value = props.form as { columns: []; name_zh: ''; remark: ''; name: ''; project: ''; dir: '' };
 form.value = props.form as { columns: []; name_zh: ''; remark: ''; name: ''; project: ''; dir: '' };
+console.log(form.value.columns.length);
+
 const rules = reactive<FormRules>({
 const rules = reactive<FormRules>({
   name: [{ required: true, message: '表名', trigger: 'blur' }],
   name: [{ required: true, message: '表名', trigger: 'blur' }],
 });
 });
@@ -143,10 +154,16 @@ const toAdd = () => {
   list.push({ index: false, required: false, type: 'String' });
   list.push({ index: false, required: false, type: 'String' });
 };
 };
 // 删除字段
 // 删除字段
-const toDel = (row: { title: String }) => {
+const toDel = (row: { title: string }) => {
   let info = form.value.columns.filter((i: any) => i.title != row.title);
   let info = form.value.columns.filter((i: any) => i.title != row.title);
   form.value.columns = info;
   form.value.columns = info;
 };
 };
+const toUp = (type: string, $index: number, row: any) => {
+  let list: Array<Arr> = form.value.columns;
+  list.splice($index, 1);
+  if (type == 'up') list.splice($index - 1, 0, row);
+  else if (type == 'down') list.splice($index + 1, 0, row);
+};
 // 提交
 // 提交
 const submitForm = async (formEl: FormInstance | undefined) => {
 const submitForm = async (formEl: FormInstance | undefined) => {
   if (!formEl) return;
   if (!formEl) return;
@@ -205,4 +222,7 @@ const toBack = () => {
 .el-button + .el-button {
 .el-button + .el-button {
   margin-left: 0;
   margin-left: 0;
 }
 }
+.propbtn {
+  display: flex;
+}
 </style>
 </style>

+ 45 - 2
src/views/parts/table-1.vue

@@ -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="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="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="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="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>
             <el-button link type="danger" @click.prevent="toDel(scope.row)" v-if="scope.row.type == 'table'">删除</el-button>
           </template>
           </template>
@@ -33,6 +33,7 @@
 </template>
 </template>
 <script setup lang="ts">
 <script setup lang="ts">
 import { ref } from 'vue';
 import { ref } from 'vue';
+import _ from 'lodash';
 import type { Ref } from 'vue';
 import type { Ref } from 'vue';
 import { useCounterStore as useStore } from '@/stores/counter';
 import { useCounterStore as useStore } from '@/stores/counter';
 import type { IQueryResult } from '@/util/types.util';
 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>
 </script>
 
 
 <style scoped>
 <style scoped>