Administrator 1 год назад
Родитель
Сommit
c90a336bd6
2 измененных файлов с 26 добавлено и 4 удалено
  1. 1 4
      file/static/search.html
  2. 25 0
      router/FileRouter.go

+ 1 - 4
file/static/search.html

@@ -25,7 +25,7 @@
                 {{if ne .historicalPrices .price }}
                 <div >
                     <div class="goods--original-price">¥{{ .historicalPrices }}</div>
-                    <div class="goods-discount-percentage">{1{ discountPrice }}</div>
+                    <div class="goods-discount-percentage">{{discalc .price .historicalPrices }}</div>
                 </div>
                 {{else}}
                 <div >
@@ -35,9 +35,6 @@
             </div>
             {{end}}
         </div>
-        <!--      <el-pagination :current-article="vo.pageNum" :article-size="vo.pageSize" :total="vo.total"-->
-        <!--                     :article-sizes="[12, 24, 36, 48]" @size-change="GetSearch" @current-change="GetSearch"-->
-        <!--                     layout="total, sizes, prev, pager, next, jumper"></el-pagination>-->
         <div class="search-pagination">
             {{if gt .count 11}}
             <el-pagination background

+ 25 - 0
router/FileRouter.go

@@ -1,9 +1,12 @@
 package router
 
 import (
+	"demo/share"
 	"errors"
 	"fmt"
 	"github.com/gin-gonic/gin"
+	"github.com/spf13/cast"
+	"os"
 	"time"
 )
 
@@ -19,6 +22,7 @@ func FileRouter(engine *gin.RouterGroup) {
 		//文章上传
 		//user.POST("/upload", uploadHandler)
 		PushRouter(user, "POST", "/upload", uploadHandler)
+		PushRouter(user, "DELETE", "", DeleteFile)
 	}
 }
 
@@ -52,3 +56,24 @@ func uploadHandler(c *gin.Context) {
 		"url": "/api/static/" + header.Filename,
 	}))
 }
+
+// DeleteFile 文件上传
+func DeleteFile(c *gin.Context) {
+	data := share.GetJsonAnyParam(c)
+	fileUrl, _ := data("fileUrl")
+	s, err := os.Stat(cast.ToString(fileUrl))
+	if os.IsNotExist(err) {
+		c.JSON(200, CreateResultError(400, "文件不存在"))
+		return
+	}
+	if s.IsDir() {
+		c.JSON(200, CreateResultError(400, "路径不存在"))
+		return
+	}
+	err = os.Remove(cast.ToString(fileUrl))
+	if err != nil {
+		c.JSON(200, CreateResultError(400, "删除失败"))
+		return
+	}
+	c.JSON(200, CreateResult())
+}