mirror of
https://gitee.com/xiangheng/x_admin.git
synced 2025-10-06 00:27:00 +08:00
优化与升级依赖
This commit is contained in:
@@ -16,8 +16,8 @@
|
|||||||
"@highlightjs/vue-plugin": "^2.1.0",
|
"@highlightjs/vue-plugin": "^2.1.0",
|
||||||
"@logicflow/core": "^1.2.22",
|
"@logicflow/core": "^1.2.22",
|
||||||
"@logicflow/extension": "^1.2.22",
|
"@logicflow/extension": "^1.2.22",
|
||||||
"@vue/shared": "^3.4.19",
|
"@vue/shared": "^3.4.20",
|
||||||
"@vueuse/core": "^10.7.2",
|
"@vueuse/core": "^10.8.0",
|
||||||
"@wangeditor/editor": "^5.1.23",
|
"@wangeditor/editor": "^5.1.23",
|
||||||
"@wangeditor/editor-for-vue": "^5.1.12",
|
"@wangeditor/editor-for-vue": "^5.1.12",
|
||||||
"axios": "^1.6.7",
|
"axios": "^1.6.7",
|
||||||
@@ -32,17 +32,17 @@
|
|||||||
"pinia": "^2.1.7",
|
"pinia": "^2.1.7",
|
||||||
"query-string": "^8.2.0",
|
"query-string": "^8.2.0",
|
||||||
"vform3-builds": "^3.0.10",
|
"vform3-builds": "^3.0.10",
|
||||||
"vue": "^3.4.19",
|
"vue": "^3.4.20",
|
||||||
"vue-clipboard3": "^2.0.0",
|
"vue-clipboard3": "^2.0.0",
|
||||||
"vue-echarts": "^6.6.9",
|
"vue-echarts": "^6.6.9",
|
||||||
"vue-router": "^4.2.5",
|
"vue-router": "^4.3.0",
|
||||||
"vue3-video-play": "^1.3.2",
|
"vue3-video-play": "^1.3.2",
|
||||||
"vuedraggable": "^4.1.0"
|
"vuedraggable": "^4.1.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@rushstack/eslint-patch": "^1.7.2",
|
"@rushstack/eslint-patch": "^1.7.2",
|
||||||
"@types/lodash-es": "^4.17.12",
|
"@types/lodash-es": "^4.17.12",
|
||||||
"@types/node": "^20.11.19",
|
"@types/node": "^20.11.20",
|
||||||
"@types/nprogress": "^0.2.3",
|
"@types/nprogress": "^0.2.3",
|
||||||
"@vitejs/plugin-vue": "^5.0.4",
|
"@vitejs/plugin-vue": "^5.0.4",
|
||||||
"@vitejs/plugin-vue-jsx": "^3.1.0",
|
"@vitejs/plugin-vue-jsx": "^3.1.0",
|
||||||
@@ -50,19 +50,19 @@
|
|||||||
"@vue/eslint-config-typescript": "^12.0.0",
|
"@vue/eslint-config-typescript": "^12.0.0",
|
||||||
"@vue/tsconfig": "^0.5.1",
|
"@vue/tsconfig": "^0.5.1",
|
||||||
"autoprefixer": "^10.4.17",
|
"autoprefixer": "^10.4.17",
|
||||||
"eslint": "^8.56.0",
|
"eslint": "^8.57.0",
|
||||||
"eslint-plugin-vue": "^9.21.1",
|
"eslint-plugin-vue": "^9.22.0",
|
||||||
"execa": "^8.0.1",
|
"execa": "^8.0.1",
|
||||||
"fs-extra": "^11.2.0",
|
"fs-extra": "^11.2.0",
|
||||||
"postcss": "^8.4.35",
|
"postcss": "^8.4.35",
|
||||||
"prettier": "^3.2.5",
|
"prettier": "^3.2.5",
|
||||||
"rollup-plugin-visualizer": "^5.12.0",
|
"rollup-plugin-visualizer": "^5.12.0",
|
||||||
"sass": "^1.71.0",
|
"sass": "^1.71.1",
|
||||||
"tailwindcss": "^3.4.1",
|
"tailwindcss": "^3.4.1",
|
||||||
"typescript": "~5.3.3",
|
"typescript": "~5.3.3",
|
||||||
"unplugin-auto-import": "^0.17.5",
|
"unplugin-auto-import": "^0.17.5",
|
||||||
"unplugin-vue-components": "^0.26.0",
|
"unplugin-vue-components": "^0.26.0",
|
||||||
"vite": "^5.1.3",
|
"vite": "^5.1.4",
|
||||||
"vite-plugin-compression": "^0.5.1",
|
"vite-plugin-compression": "^0.5.1",
|
||||||
"vite-plugin-style-import": "^2.0.0",
|
"vite-plugin-style-import": "^2.0.0",
|
||||||
"vite-plugin-svg-icons": "^2.0.1",
|
"vite-plugin-svg-icons": "^2.0.1",
|
||||||
|
@@ -159,4 +159,9 @@ export default defineComponent({
|
|||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss"></style>
|
<style lang="scss" scoped>
|
||||||
|
.upload {
|
||||||
|
display: inline-block;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
@@ -32,15 +32,21 @@
|
|||||||
</template>
|
</template>
|
||||||
新增
|
新增
|
||||||
</el-button>
|
</el-button>
|
||||||
|
|
||||||
<upload
|
<upload
|
||||||
class="mr-3"
|
class="ml-3 mr-3"
|
||||||
:url="adminImportFile"
|
:url="adminImportFile"
|
||||||
:data="{ cid: 0 }"
|
:data="{ cid: 0 }"
|
||||||
type="file"
|
type="file"
|
||||||
:show-progress="true"
|
:show-progress="true"
|
||||||
@change="resetPage"
|
@change="resetPage"
|
||||||
>
|
>
|
||||||
<el-button type="primary">导入</el-button>
|
<el-button type="primary">
|
||||||
|
<template #icon>
|
||||||
|
<icon name="el-icon-Upload" />
|
||||||
|
</template>
|
||||||
|
导入
|
||||||
|
</el-button>
|
||||||
</upload>
|
</upload>
|
||||||
|
|
||||||
<el-button type="primary" @click="exportFile">
|
<el-button type="primary" @click="exportFile">
|
||||||
|
@@ -1,9 +1,7 @@
|
|||||||
package admin
|
package admin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"x_admin/config"
|
"x_admin/config"
|
||||||
@@ -14,7 +12,6 @@ import (
|
|||||||
"x_admin/util"
|
"x_admin/util"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/xuri/excelize/v2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// func AdminRoute(rg *gin.RouterGroup) {
|
// func AdminRoute(rg *gin.RouterGroup) {
|
||||||
@@ -74,39 +71,39 @@ func (ah AdminHandler) ExportFile(c *gin.Context) {
|
|||||||
|
|
||||||
// 导入文件
|
// 导入文件
|
||||||
func (ah AdminHandler) ImportFile(c *gin.Context) {
|
func (ah AdminHandler) ImportFile(c *gin.Context) {
|
||||||
// file, err := c.FormFile("file")
|
|
||||||
// if err != nil {
|
|
||||||
// c.String(500, "上传文件出错")
|
|
||||||
// }
|
|
||||||
// fmt.Println(file)
|
|
||||||
|
|
||||||
// 单文件
|
|
||||||
file, _, err := c.Request.FormFile("file")
|
file, _, err := c.Request.FormFile("file")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.FailWithMsg(c, response.SystemError, "文件不存在")
|
c.String(http.StatusInternalServerError, "文件不存在")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
// 创建缓冲区
|
|
||||||
buf := new(bytes.Buffer)
|
|
||||||
|
|
||||||
// 将文件内容复制到缓冲区
|
|
||||||
_, err = io.Copy(buf, file)
|
|
||||||
if err != nil {
|
|
||||||
c.String(http.StatusInternalServerError, "Failed to read file")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// 创建Excel文件对象
|
|
||||||
f, err := excelize.OpenReader(bytes.NewReader(buf.Bytes()))
|
|
||||||
if err != nil {
|
|
||||||
c.String(http.StatusInternalServerError, "Failed to open Excel file")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
importList := []SystemAuthAdminResp{}
|
importList := []SystemAuthAdminResp{}
|
||||||
err = excel.ImportExcel(f, &importList, 1, 2)
|
err = excel.GetExcelData(file, &importList)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
c.String(http.StatusInternalServerError, err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// // 创建缓冲区
|
||||||
|
// buf := new(bytes.Buffer)
|
||||||
|
|
||||||
|
// // 将文件内容复制到缓冲区
|
||||||
|
// _, err = io.Copy(buf, file)
|
||||||
|
// if err != nil {
|
||||||
|
// c.String(http.StatusInternalServerError, "读取失败")
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
// // 创建Excel文件对象
|
||||||
|
// f, err := excelize.OpenReader(bytes.NewReader(buf.Bytes()))
|
||||||
|
// if err != nil {
|
||||||
|
// c.String(http.StatusInternalServerError, "Excel读取失败")
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
|
||||||
|
// err = excel.ImportExcel(f, &importList, 1, 2)
|
||||||
|
// if err != nil {
|
||||||
|
// fmt.Println(err)
|
||||||
|
// }
|
||||||
for _, t := range importList {
|
for _, t := range importList {
|
||||||
fmt.Printf("%#v", t)
|
fmt.Printf("%#v", t)
|
||||||
}
|
}
|
||||||
|
@@ -1,13 +1,44 @@
|
|||||||
package excel
|
package excel
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"mime/multipart"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/xuri/excelize/v2"
|
"github.com/xuri/excelize/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func GetExcelData(file multipart.File, dst interface{}) (err error) {
|
||||||
|
// 创建缓冲区
|
||||||
|
buf := new(bytes.Buffer)
|
||||||
|
|
||||||
|
// 将文件内容复制到缓冲区
|
||||||
|
_, err = io.Copy(buf, file)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
// c.String(http.StatusInternalServerError, "读取失败")
|
||||||
|
err = errors.New("读取失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 创建Excel文件对象
|
||||||
|
f, err := excelize.OpenReader(bytes.NewReader(buf.Bytes()))
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
// c.String(http.StatusInternalServerError, "Excel读取失败")
|
||||||
|
err = errors.New("Excel读取失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = ImportExcel(f, dst, 1, 2)
|
||||||
|
// if err != nil {
|
||||||
|
// fmt.Println(err)
|
||||||
|
// }
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// ImportExcel 导入数据(单个sheet)
|
// ImportExcel 导入数据(单个sheet)
|
||||||
// 需要在传入的结构体中的字段加上tag:excel:"title:列头名称;"
|
// 需要在传入的结构体中的字段加上tag:excel:"title:列头名称;"
|
||||||
// f 获取到的excel对象、dst 导入目标对象【传指针】
|
// f 获取到的excel对象、dst 导入目标对象【传指针】
|
||||||
@@ -116,17 +147,24 @@ func importData(f *excelize.File, dst interface{}, sheetName string, headIndex,
|
|||||||
cellValue = row[index] // 获取单元格的值
|
cellValue = row[index] // 获取单元格的值
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fmt.Println("Type.Name:", field.Type.Name(), field.Type.Kind())
|
||||||
// 根据字段类型设置值
|
// 根据字段类型设置值
|
||||||
switch field.Type.Kind() {
|
switch field.Type.Kind() {
|
||||||
case reflect.Int:
|
case reflect.Int:
|
||||||
v, _ := strconv.ParseInt(cellValue, 10, 64)
|
v, _ := strconv.ParseInt(cellValue, 10, 64)
|
||||||
newData.Field(i).SetInt(v)
|
newData.Field(i).SetInt(v)
|
||||||
|
case reflect.Int64:
|
||||||
|
v, _ := strconv.ParseInt(cellValue, 10, 64)
|
||||||
|
newData.Field(i).SetInt(v)
|
||||||
case reflect.Uint:
|
case reflect.Uint:
|
||||||
v, _ := strconv.ParseUint(cellValue, 10, 64)
|
v, _ := strconv.ParseUint(cellValue, 10, 64)
|
||||||
newData.Field(i).SetUint(v)
|
newData.Field(i).SetUint(v)
|
||||||
// case reflect.Uint8:
|
case reflect.Uint8:
|
||||||
// v, _ := strconv.ParseUint(cellValue, 10, 64)
|
v, _ := strconv.ParseUint(cellValue, 10, 64)
|
||||||
// newData.Field(i).SetUint(v)
|
newData.Field(i).SetUint(v)
|
||||||
|
case reflect.Uint16:
|
||||||
|
v, _ := strconv.ParseUint(cellValue, 10, 64)
|
||||||
|
newData.Field(i).SetUint(v)
|
||||||
case reflect.String:
|
case reflect.String:
|
||||||
newData.Field(i).SetString(cellValue)
|
newData.Field(i).SetString(cellValue)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user