ZaiZai 1 éve
szülő
commit
b5370d51c4

+ 19 - 1
src/api/modules/project/project.js

@@ -9,7 +9,7 @@ export default {
             data: form,
         }, false)
     },
-   
+
     //新增
     async add(form) {
         return HcApi({
@@ -58,4 +58,22 @@ export default {
             data: { ids },
         }, false)
     },
+    //下载模板
+    async exportTemplate() {
+        return HcApi({
+            url: '/api/blade-attach/project/export-template',
+            method: 'get',
+            params: {},
+            responseType: 'blob',
+        }, false)
+    },
+    //导出
+    async exportWorkfocus(ids) {
+        return HcApi({
+            url: '/api/blade-attach/project/export-workfocus',
+            method: 'get',
+            params: { id_equal: ids },
+            responseType: 'blob',
+        }, false)
+    },
 }

+ 43 - 14
src/views/project/admin/list.vue

@@ -74,12 +74,12 @@
         <hc-dialog v-model="isImportShow" widths="24rem" title="项目数据导入" :footer="false" @close="modalImportClose">
             <hc-form-upload
                 v-model="importFile" class="hc-form-drop-upload"
-                :options="{ num: 0, type: 'list', drop: true }"
-                :upload="{ options: uploadOptions }"
+                :options="{ num: 1, type: 'list', drop: true }"
+                :upload="{ options: uploadOptions }" @success="uploadSuccess"
             />
             <div class="hc-flex mt-5">
                 <span class="mr-2">模板下载:</span>
-                <el-button color="#20C98B" size="small" class="text-white">点击下载</el-button>
+                <el-button color="#20C98B" size="small" class="text-white" :loading="downloadTemplateLoading" @click="downloadTemplate">点击下载</el-button>
             </div>
         </hc-dialog>
     </hc-card>
@@ -88,19 +88,18 @@
 <script setup>
 import { onMounted, ref } from 'vue'
 import HcTableList from '../modules/project-list.vue'
-import { arrToId, getArrValue } from 'js-fast-way'
-import mainApi from '~api/project/project'
+import { arrToId, getArrValue, newDownBlob } from 'js-fast-way'
 import { getDictionaryData } from '~src/utils/tools'
+import mainApi from '~api/project/project'
+import { useClick } from 'hc-vue3-ui'
 
 //事件
 const emit = defineEmits(['edit'])
 //渲染完成
 onMounted(async () => {
-
-  await getProStation()
-   await getProType()
-   getTableData()
-
+    await getProStation()
+    await getProType()
+    getTableData().then()
 })
 const tableRef = ref(null)
 const buildTotal = ref(0)
@@ -162,7 +161,6 @@ const rowNameClick = (row) => {
     emit('edit', row)
 }
 
-//批量删除
 //批量删除
 const delTableItem = async (_, resolve) => {
     const ids = arrToId(tableCheckKeys.value)
@@ -172,15 +170,22 @@ const delTableItem = async (_, resolve) => {
         resolve()
         searchClick()
     } else {
-
         window.$message.error(msg ?? '删除失败')
         resolve()
     }
 }
 
 //批量导出
-const deriveTableItem = (_, resolve) => {
-    tableRef.value?.batchExport()
+const deriveTableItem = async (_, resolve) => {
+    /*const ids = arrToId(tableCheckKeys.value)
+    const { error, val } = await mainApi.exportWorkfocus(ids)
+    if (error) {
+        window.$message?.error('数据异常')
+        resolve()
+        return
+    }
+    await newDownBlob(val)*/
+    window.$message?.error('暂未开放')
     resolve()
 }
 
@@ -221,6 +226,8 @@ const reportsModalClose = () => {
 const isImportShow = ref(false)
 const importFile = ref([])
 const uploadOptions = {
+    url: '/api/blade-attach/project/import-project',
+    size: 120,
     accept: '.xls,.xlsx',
     accept_tip: '请选择Excel文件',
 }
@@ -232,6 +239,28 @@ const importClick = () => {
 const modalImportClose = () => {
     isImportShow.value = false
 }
+
+//下载模板
+const downloadTemplateLoading = ref(false)
+const downloadTemplate = async () => {
+    await useClick() //这里要使用 await 来等待
+    downloadTemplateLoading.value = true
+    const { error, val } = await mainApi.exportTemplate()
+    downloadTemplateLoading.value = false
+    if (error) {
+        window.$message?.error('数据异常')
+        return
+    }
+    await newDownBlob(val)
+}
+
+//上传完成
+const uploadSuccess = () => {
+    setTimeout(() => {
+        getTableData()
+        modalImportClose()
+    }, 1000)
+}
 </script>
 
 <style lang="scss">

+ 10 - 29
src/views/project/modules/project-list.vue

@@ -236,7 +236,7 @@
 <script setup>
 import { onMounted, ref, watch } from 'vue'
 import mainApi from '~api/project/project'
-import { getArrValue, getObjValue } from 'js-fast-way'
+import { arrToId, getArrValue, getObjValue, newDownBlob } from 'js-fast-way'
 import BigNumber from 'bignumber.js'
 
 const props = defineProps({
@@ -359,7 +359,6 @@ const delTableItem = async ({ item }, resolve) => {
         resolve()
         emit('change')
     } else {
-
         window.$message.error(msg ?? '删除失败')
         resolve()
     }
@@ -373,26 +372,16 @@ const drawerCancel = () => {
 
 
 //导出数据
-const deriveTableItem = ({ item }, resolve) => {
-    console.log('我被执行了', item)
-    //这里可以写一些操作,下面是模拟3秒关闭
-    setTimeout(() => {
+const deriveTableItem = async ({ item }, resolve) => {
+    /*const { error, val } = await mainApi.exportWorkfocus(item.id)
+    if (error) {
+        window.$message?.error('数据异常')
         resolve()
-        emit('export', item)
-    }, 3000)
-}
-
-//批量删除
-const batchRemove = () => {
-    if (!isAdminAuth.value) return
-    const rows = tableCheckKeys.value
-    console.log('批量删除', rows)
-}
-
-//批量导出
-const batchExport = () => {
-    const rows = tableCheckKeys.value
-    console.log('批量导出', rows)
+        return
+    }
+    await newDownBlob(val)*/
+    window.$message?.error('暂未开放')
+    resolve()
 }
 
 //年数据
@@ -400,18 +389,14 @@ const yearKey = ref('2023')
 const yearData = ref({})
 const yearIndex = ref(-1)
 const yearChange = (_, index) => {
-
     yearIndex.value = index
 }
 
-
 //合并列或行
 const tableYearMethod = ({ rowIndex, columnIndex }) => {
     return setSpanMethod(columnIndex, rowIndex)
 }
 
-
-
 //合并列或行
 const tableYearMethod1 = ({ rowIndex, columnIndex }) => {
     return setSpanMethod(columnIndex, rowIndex, false)
@@ -553,10 +538,6 @@ const changePlanRatio = (val, row, index)=>{
         }
     }*/
 }
-defineExpose({
-    batchRemove,
-    batchExport,
-})
 </script>
 
 <style lang="scss">