From 42b6668fd042f2d0ecdbcc4b401b4a05055b53c8 Mon Sep 17 00:00:00 2001
From: 疯狂的狮子Li <15040126243@163.com>
Date: 星期四, 28 十一月 2024 11:16:00 +0800
Subject: [PATCH] fix 修复 变量code错误
---
src/views/system/user/profile/userAvatar.vue | 147 ++++++++++++++++++++++++++----------------------
1 files changed, 79 insertions(+), 68 deletions(-)
diff --git a/src/views/system/user/profile/userAvatar.vue b/src/views/system/user/profile/userAvatar.vue
index f576c95..32b6f5c 100644
--- a/src/views/system/user/profile/userAvatar.vue
+++ b/src/views/system/user/profile/userAvatar.vue
@@ -1,20 +1,20 @@
<template>
<div class="user-info-head" @click="editCropper()">
<img :src="options.img" title="鐐瑰嚮涓婁紶澶村儚" class="img-circle img-lg" />
- <el-dialog :title="title" v-model="open" width="800px" append-to-body @opened="modalOpened" @close="closeDialog">
+ <el-dialog v-model="open" :title="title" width="800px" append-to-body @opened="modalOpened" @close="closeDialog">
<el-row>
<el-col :xs="24" :md="12" :style="{ height: '350px' }">
<vue-cropper
+ v-if="visible"
ref="cropper"
:img="options.img"
:info="true"
- :autoCrop="options.autoCrop"
- :autoCropWidth="options.autoCropWidth"
- :autoCropHeight="options.autoCropHeight"
- :fixedBox="options.fixedBox"
- :outputType="options.outputType"
- @realTime="realTime"
- v-if="visible"
+ :auto-crop="options.autoCrop"
+ :auto-crop-width="options.autoCropWidth"
+ :auto-crop-height="options.autoCropHeight"
+ :fixed-box="options.fixedBox"
+ :output-type="options.outputType"
+ @real-time="realTime"
/>
</el-col>
<el-col :xs="24" :md="12" :style="{ height: '350px' }">
@@ -26,15 +26,12 @@
<br />
<el-row>
<el-col :lg="2" :md="2">
- <el-upload
- action="#"
- :http-request="requestUpload"
- :show-file-list="false"
- :before-upload="beforeUpload"
- >
+ <el-upload action="#" :http-request="requestUpload" :show-file-list="false" :before-upload="beforeUpload">
<el-button>
閫夋嫨
- <el-icon class="el-icon--right"><Upload /></el-icon>
+ <el-icon class="el-icon--right">
+ <Upload />
+ </el-icon>
</el-button>
</el-upload>
</el-col>
@@ -58,93 +55,107 @@
</div>
</template>
-<script setup>
-import "vue-cropper/dist/index.css";
-import { VueCropper } from "vue-cropper";
-import { uploadAvatar } from "@/api/system/user";
-import useUserStore from "@/store/modules/user";
+<script setup lang="ts">
+import 'vue-cropper/dist/index.css';
+import { VueCropper } from 'vue-cropper';
+import { uploadAvatar } from '@/api/system/user';
+import useUserStore from '@/store/modules/user';
+import { UploadRawFile } from 'element-plus';
+
+interface Options {
+ img: string | any; // 瑁佸壀鍥剧墖鐨勫湴鍧�
+ autoCrop: boolean; // 鏄惁榛樿鐢熸垚鎴浘妗�
+ autoCropWidth: number; // 榛樿鐢熸垚鎴浘妗嗗搴�
+ autoCropHeight: number; // 榛樿鐢熸垚鎴浘妗嗛珮搴�
+ fixedBox: boolean; // 鍥哄畾鎴浘妗嗗ぇ灏� 涓嶅厑璁告敼鍙�
+ fileName: string;
+ previews: any; // 棰勮鏁版嵁
+ outputType: string;
+ visible: boolean;
+}
const userStore = useUserStore();
-const { proxy } = getCurrentInstance();
+const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const open = ref(false);
const visible = ref(false);
-const title = ref("淇敼澶村儚");
+const title = ref('淇敼澶村儚');
+const cropper = ref<any>({});
//鍥剧墖瑁佸壀鏁版嵁
-const options = reactive({
- img: userStore.avatar, // 瑁佸壀鍥剧墖鐨勫湴鍧�
- autoCrop: true, // 鏄惁榛樿鐢熸垚鎴浘妗�
- autoCropWidth: 200, // 榛樿鐢熸垚鎴浘妗嗗搴�
- autoCropHeight: 200, // 榛樿鐢熸垚鎴浘妗嗛珮搴�
- fixedBox: true, // 鍥哄畾鎴浘妗嗗ぇ灏� 涓嶅厑璁告敼鍙�
- outputType: "png", // 榛樿鐢熸垚鎴浘涓篜NG鏍煎紡
- filename: '',
- previews: {} //棰勮鏁版嵁
+const options = reactive<Options>({
+ img: userStore.avatar,
+ autoCrop: true,
+ autoCropWidth: 200,
+ autoCropHeight: 200,
+ fixedBox: true,
+ outputType: 'png',
+ fileName: '',
+ previews: {},
+ visible: false
});
/** 缂栬緫澶村儚 */
-function editCropper() {
+const editCropper = () => {
open.value = true;
-}
+};
/** 鎵撳紑寮瑰嚭灞傜粨鏉熸椂鐨勫洖璋� */
-function modalOpened() {
+const modalOpened = () => {
visible.value = true;
-}
+};
/** 瑕嗙洊榛樿涓婁紶琛屼负 */
-function requestUpload() {}
+const requestUpload = (): any => {};
/** 鍚戝乏鏃嬭浆 */
-function rotateLeft() {
- proxy.$refs.cropper.rotateLeft();
-}
+const rotateLeft = () => {
+ cropper.value.rotateLeft();
+};
/** 鍚戝彸鏃嬭浆 */
-function rotateRight() {
- proxy.$refs.cropper.rotateRight();
-}
+const rotateRight = () => {
+ cropper.value.rotateRight();
+};
/** 鍥剧墖缂╂斁 */
-function changeScale(num) {
+const changeScale = (num: number) => {
num = num || 1;
- proxy.$refs.cropper.changeScale(num);
-}
+ cropper.value.changeScale(num);
+};
/** 涓婁紶棰勫鐞� */
-function beforeUpload(file) {
- if (file.type.indexOf("image/") == -1) {
- proxy.$modal.msgError("鏂囦欢鏍煎紡閿欒锛岃涓婁紶鍥剧墖绫诲瀷,濡傦細JPG锛孭NG鍚庣紑鐨勬枃浠躲��");
+const beforeUpload = (file: UploadRawFile): any => {
+ if (file.type.indexOf('image/') == -1) {
+ proxy?.$modal.msgError('鏂囦欢鏍煎紡閿欒锛岃涓婁紶鍥剧墖绫诲瀷,濡傦細JPG锛孭NG鍚庣紑鐨勬枃浠躲��');
} else {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => {
options.img = reader.result;
- options.filename = file.name;
+ options.fileName = file.name;
};
}
-}
+};
/** 涓婁紶鍥剧墖 */
-function uploadImg() {
- proxy.$refs.cropper.getCropBlob(data => {
+const uploadImg = async () => {
+ cropper.value.getCropBlob(async (data: any) => {
let formData = new FormData();
- formData.append("avatarfile", data, options.filename);
- uploadAvatar(formData).then(response => {
- open.value = false;
- options.img = response.data.imgUrl;
- userStore.avatar = options.img;
- proxy.$modal.msgSuccess("淇敼鎴愬姛");
- visible.value = false;
- });
+ formData.append('avatarfile', data, options.fileName);
+ const res = await uploadAvatar(formData);
+ open.value = false;
+ options.img = res.data.imgUrl;
+ userStore.setAvatar(options.img);
+ proxy?.$modal.msgSuccess('淇敼鎴愬姛');
+ visible.value = false;
});
-}
+};
/** 瀹炴椂棰勮 */
-function realTime(data) {
+const realTime = (data: any) => {
options.previews = data;
-}
+};
/** 鍏抽棴绐楀彛 */
-function closeDialog() {
+const closeDialog = () => {
options.img = userStore.avatar;
options.visible = false;
-}
+};
</script>
-<style lang='scss' scoped>
+<style lang="scss" scoped>
.user-info-head {
position: relative;
display: inline-block;
@@ -152,7 +163,7 @@
}
.user-info-head:hover:after {
- content: "+";
+ content: '+';
position: absolute;
left: 0;
right: 0;
@@ -168,4 +179,4 @@
line-height: 110px;
border-radius: 50%;
}
-</style>
\ No newline at end of file
+</style>
--
Gitblit v1.9.3