Explorar el Código

读取文件修改

huangyan hace 1 año
padre
commit
4c69d693a5
Se han modificado 1 ficheros con 17 adiciones y 18 borrados
  1. 17 18
      app/src/App.vue

+ 17 - 18
app/src/App.vue

@@ -257,7 +257,7 @@
     <!-- 保存 -->
     <el-dialog v-model="saveJson" title="保存文件" :width="800">
       <el-switch v-model="filetype" style="--el-switch-on-color: #13ce66; --el-switch-off-color: #00ffff"
-        active-text="文件" inactive-text="模板" @click="templateItems" />
+        active-text="文件" inactive-text="模板"/>
       <el-input v-model="saveFileName" style="width: 150px; margin-right: 10px" placeholder="请输入文件名"
         clearable></el-input>
       <el-button type="primary" @click="save">保存文件</el-button>
@@ -553,7 +553,6 @@ const importFromJsonServer = async (itemId) => {
     if (response.ok) {
       const jsonData = await response.json()
       // const jsonObject = JSON.parse(jsonData.data)
-      console.log(jsonData.data.data)
       app.setData(jsonData.data.data)
       filelist.value = false
       ElNotification.success('导入成功')
@@ -578,13 +577,8 @@ const searchTemplate = async () => {
       const jsonData = await response.json()
       if (jsonData.code === 200) {
         names.clear()
-        const defaultUrl = 'https://erp.baozhida.cn/assets/icon-91f5d92f.png';
         for (let index = 0; index < jsonData.data.length; index++) {
-          if (jsonData.data[index].data.elements.length === 2) {
-            names.set(jsonData.data[index].name, jsonData.data[index].data.elements[0].url)
-          } else {
-            names.set(jsonData.data[index].name, defaultUrl)
-          }
+          names.set(jsonData.data[index].name, jsonData.data[index].url)
         }
         ElNotification.success('搜索成功')
         search.value = null
@@ -657,6 +651,10 @@ const handleExportCommand = type => {
 }
 //保存为json文件
 const save = async () => {
+  if (saveFileName.value === null) {
+    ElNotification.warning('请输入文件名')
+    return
+  }
   try {
     const response = await fetch('http://localhost:8080/api/savefile', {
       method: 'POST',
@@ -671,12 +669,19 @@ const save = async () => {
       })
     })
     if (!response.ok) throw new Error('Failed to fetch JSON data')
-    ElNotification.success('保存成功')
-    //重置状态
+    const data = await response.json()
+    if (data.code !== 200) {
+      ElNotification.error(data.message)
+    }else{
+      ElNotification.success('保存成功')
+      //重置状态
     saveFileName.value = null
     saveJson.value = false
+    }
   } catch (error) {
+    ElNotification.error(data.message)
     console.log(error)
+
   }
 }
 
@@ -684,7 +689,6 @@ const templateItems = async () => {
   const requestBody = {
     type: filetype.value,
   };
-  const defaultUrl = 'https://erp.baozhida.cn/assets/icon-91f5d92f.png'; // 替换为实际的默认URL
   names.clear() //清空map 重新渲染
   try {
     const response = await fetch('http://localhost:8080/api/template', {
@@ -698,14 +702,8 @@ const templateItems = async () => {
     if (response.ok) {
       const jsonData = await response.json()
       if (jsonData.code === 200) {
-        names.clear()
-        const defaultUrl = 'https://erp.baozhida.cn/assets/icon-91f5d92f.png';
         for (let index = 0; index < jsonData.data.length; index++) {
-          if (jsonData.data[index].data.elements.length === 2) {
-            names.set(jsonData.data[index].name, jsonData.data[index].data.elements[0].url)
-          } else {
-            names.set(jsonData.data[index].name, defaultUrl)
-          }
+          names.set(jsonData.data[index].name, jsonData.data[index].url)
         }
         ElNotification.success('获取成功')
         search.value = null
@@ -713,6 +711,7 @@ const templateItems = async () => {
         ElNotification.warning('文件不存在')
       }
     }
+   
   } catch (error) {
     ElNotification.warning('获取失败')
     console.log(error);