Browse Source
Merge branches 'develop' and 'gin-vue-admin_v2_dev' of https://github.com/flipped-aurora/gin-vue-admin into gin-vue-admin_v2_dev
main
Merge branches 'develop' and 'gin-vue-admin_v2_dev' of https://github.com/flipped-aurora/gin-vue-admin into gin-vue-admin_v2_dev
main
QM303176530
4 years ago
17 changed files with 588 additions and 382 deletions
-
14server/api/v1/exa_file_upload_download.go
-
12server/api/v1/sys_user.go
-
68server/config.yaml
-
8server/config/config.go
-
4server/initialize/router.go
-
53server/utils/upload_avatar_local.go
-
53server/utils/upload_file_local.go
-
2server/utils/upload_remote.go
-
423web/package-lock.json
-
2web/package.json
-
BINweb/src/assets/noBody.png
-
75web/src/components/customPic/index.vue
-
11web/src/view/example/upload/upload.vue
-
15web/src/view/layout/index.vue
-
7web/src/view/person/person.vue
-
6web/src/view/superAdmin/user/user.vue
-
217web/src/view/systemTools/system/system.vue
@ -0,0 +1,53 @@ |
|||
package utils |
|||
|
|||
import ( |
|||
"gin-vue-admin/global" |
|||
"io" |
|||
"mime/multipart" |
|||
"os" |
|||
"path" |
|||
"strings" |
|||
"time" |
|||
) |
|||
|
|||
func UploadAvatarLocal(file *multipart.FileHeader) (err error, localPath string, key string) { |
|||
// 读取文件后缀
|
|||
ext := path.Ext(file.Filename) |
|||
// 读取文件名并加密
|
|||
fileName := strings.TrimSuffix(file.Filename, ext) |
|||
fileName = MD5V([]byte(fileName)) |
|||
// 拼接新文件名
|
|||
lastName := fileName + "_" + time.Now().Format("20060102150405") + ext |
|||
// 读取全局变量的定义路径
|
|||
savePath := global.GVA_CONFIG.LocalUpload.AvatarPath |
|||
// 尝试创建此路径
|
|||
err = os.MkdirAll(savePath, os.ModePerm) |
|||
if err != nil{ |
|||
global.GVA_LOG.Error("upload local file fail:", err) |
|||
return err, "", "" |
|||
} |
|||
// 拼接路径和文件名
|
|||
dst := savePath + "/" + lastName |
|||
// 下面为上传逻辑
|
|||
// 打开文件 defer 关闭
|
|||
src, err := file.Open() |
|||
if err != nil { |
|||
global.GVA_LOG.Error("upload local file fail:", err) |
|||
return err, "", "" |
|||
} |
|||
defer src.Close() |
|||
// 创建文件 defer 关闭
|
|||
out, err := os.Create(dst) |
|||
if err != nil { |
|||
global.GVA_LOG.Error("upload local file fail:", err) |
|||
return err, "", "" |
|||
} |
|||
defer out.Close() |
|||
// 传输(拷贝)文件
|
|||
_, err = io.Copy(out, src) |
|||
if err != nil { |
|||
global.GVA_LOG.Error("upload local file fail:", err) |
|||
return err, "", "" |
|||
} |
|||
return nil, dst, lastName |
|||
} |
@ -0,0 +1,53 @@ |
|||
package utils |
|||
|
|||
import ( |
|||
"gin-vue-admin/global" |
|||
"io" |
|||
"mime/multipart" |
|||
"os" |
|||
"path" |
|||
"strings" |
|||
"time" |
|||
) |
|||
|
|||
func UploadFileLocal(file *multipart.FileHeader) (err error, localPath string, key string) { |
|||
// 读取文件后缀
|
|||
ext := path.Ext(file.Filename) |
|||
// 读取文件名并加密
|
|||
fileName := strings.TrimSuffix(file.Filename, ext) |
|||
fileName = MD5V([]byte(fileName)) |
|||
// 拼接新文件名
|
|||
lastName := fileName + "_" + time.Now().Format("20060102150405") + ext |
|||
// 读取全局变量的定义路径
|
|||
savePath := global.GVA_CONFIG.LocalUpload.FilePath |
|||
// 尝试创建此路径
|
|||
err = os.MkdirAll(savePath, os.ModePerm) |
|||
if err != nil{ |
|||
global.GVA_LOG.Error("upload local file fail:", err) |
|||
return err, "", "" |
|||
} |
|||
// 拼接路径和文件名
|
|||
dst := savePath + "/" + lastName |
|||
// 下面为上传逻辑
|
|||
// 打开文件 defer 关闭
|
|||
src, err := file.Open() |
|||
if err != nil { |
|||
global.GVA_LOG.Error("upload local file fail:", err) |
|||
return err, "", "" |
|||
} |
|||
defer src.Close() |
|||
// 创建文件 defer 关闭
|
|||
out, err := os.Create(dst) |
|||
if err != nil { |
|||
global.GVA_LOG.Error("upload local file fail:", err) |
|||
return err, "", "" |
|||
} |
|||
defer out.Close() |
|||
// 传输(拷贝)文件
|
|||
_, err = io.Copy(out, src) |
|||
if err != nil { |
|||
global.GVA_LOG.Error("upload local file fail:", err) |
|||
return err, "", "" |
|||
} |
|||
return nil, dst, lastName |
|||
} |
423
web/package-lock.json
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
After Width: 120 | Height: 120 | Size: 4.0 KiB |
@ -0,0 +1,75 @@ |
|||
<template> |
|||
<span class="headerAvatar"> |
|||
<template v-if="picType === 'avatar'"> |
|||
<el-avatar :size="30" :src="avatar" v-if="userInfo.headerImg"></el-avatar> |
|||
<el-avatar :size="30" :src="require('@/assets/noBody.png')" v-else></el-avatar> |
|||
</template> |
|||
<template v-if="picType === 'img'"> |
|||
<img :src="avatar" class="avatar" v-if="userInfo.headerImg" /> |
|||
<img :src="require('@/assets/noBody.png')" class="avatar" v-else/> |
|||
</template> |
|||
<template v-if="picType === 'file'"> |
|||
<img :src="file" class="file"/> |
|||
</template> |
|||
</span> |
|||
</template> |
|||
|
|||
<script> |
|||
import { mapGetters } from 'vuex' |
|||
const path = process.env.VUE_APP_BASE_API |
|||
export default { |
|||
name: "customPic", |
|||
props: { |
|||
picType: { |
|||
type: String, |
|||
required: false, |
|||
default: "avatar" |
|||
}, |
|||
picSrc: { |
|||
type: String, |
|||
required: false, |
|||
default: "" |
|||
} |
|||
}, |
|||
data(){ |
|||
return{ |
|||
path: path, |
|||
} |
|||
}, |
|||
computed:{ |
|||
...mapGetters('user', ['userInfo']), |
|||
avatar(){ |
|||
if(this.picSrc === ''){ |
|||
if(this.userInfo.headerImg !== '' && this.userInfo.headerImg.slice(0, 4) === "http"){ |
|||
return this.userInfo.headerImg |
|||
} |
|||
return this.path + this.userInfo.headerImg |
|||
}else{ |
|||
if(this.picSrc !== '' && this.picSrc.slice(0, 4) === "http"){ |
|||
return this.picSrc |
|||
} |
|||
return this.path + this.picSrc |
|||
} |
|||
}, |
|||
file(){ |
|||
if(this.picSrc && this.picSrc.slice(0, 4) !== "http"){ |
|||
return this.path + this.picSrc |
|||
} |
|||
return this.picSrc |
|||
} |
|||
} |
|||
} |
|||
</script> |
|||
|
|||
<style scoped> |
|||
.headerAvatar{ |
|||
display: flex; |
|||
justify-content: center; |
|||
align-items: center; |
|||
} |
|||
.file{ |
|||
width: 80px; |
|||
height: 80px; |
|||
position: relative; |
|||
} |
|||
</style> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue