From e2bc12d1867a5aae638c6be7e501e5c044543634 Mon Sep 17 00:00:00 2001 From: LiuHao <liuhaoai545@gmail> Date: 星期一, 17 四月 2023 22:23:18 +0800 Subject: [PATCH] update 修改 el-card shadow='hover' --- src/views/system/user/profile/userAvatar.vue | 204 +++++++++++++++++++++++++------------------------- 1 files changed, 102 insertions(+), 102 deletions(-) diff --git a/src/views/system/user/profile/userAvatar.vue b/src/views/system/user/profile/userAvatar.vue index 6094301..0af8b28 100644 --- a/src/views/system/user/profile/userAvatar.vue +++ b/src/views/system/user/profile/userAvatar.vue @@ -1,3 +1,58 @@ +<template> + <div class="user-info-head" @click="editCropper()"> + <img :src="options.img as string" title="鐐瑰嚮涓婁紶澶村儚" class="img-circle img-lg" /> + <el-dialog :title="title" v-model="open" width="800px" append-to-body @opened="modalOpened" @close="closeDialog"> + <el-row> + <el-col :xs="24" :md="12" :style="{ height: '350px' }"> + <vue-cropper + 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" + /> + </el-col> + <el-col :xs="24" :md="12" :style="{ height: '350px' }"> + <div class="avatar-upload-preview"> + <img :src="options.previews.url" :style="options.previews.img" /> + </div> + </el-col> + </el-row> + <br /> + <el-row> + <el-col :lg="2" :md="2"> + <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-button> + </el-upload> + </el-col> + <el-col :lg="{ span: 1, offset: 2 }" :md="2"> + <el-button icon="Plus" @click="changeScale(1)"></el-button> + </el-col> + <el-col :lg="{ span: 1, offset: 1 }" :md="2"> + <el-button icon="Minus" @click="changeScale(-1)"></el-button> + </el-col> + <el-col :lg="{ span: 1, offset: 1 }" :md="2"> + <el-button icon="RefreshLeft" @click="rotateLeft()"></el-button> + </el-col> + <el-col :lg="{ span: 1, offset: 1 }" :md="2"> + <el-button icon="RefreshRight" @click="rotateRight()"></el-button> + </el-col> + <el-col :lg="{ span: 2, offset: 6 }" :md="2"> + <el-button type="primary" @click="uploadImg()">鎻� 浜�</el-button> + </el-col> + </el-row> + </el-dialog> + </div> +</template> + <script setup lang="ts"> import "vue-cropper/dist/index.css"; import { VueCropper } from "vue-cropper"; @@ -6,15 +61,15 @@ import { ComponentInternalInstance } from "vue"; interface Options { - img: string | ArrayBuffer | null // 瑁佸壀鍥剧墖鐨勫湴鍧� - autoCrop: boolean // 鏄惁榛樿鐢熸垚鎴浘妗� - autoCropWidth: number // 榛樿鐢熸垚鎴浘妗嗗搴� - autoCropHeight: number // 榛樿鐢熸垚鎴浘妗嗛珮搴� - fixedBox: boolean // 鍥哄畾鎴浘妗嗗ぇ灏� 涓嶅厑璁告敼鍙� - fileName: string - previews: any // 棰勮鏁版嵁 - outputType: string - visible: boolean + img: string | ArrayBuffer | null // 瑁佸壀鍥剧墖鐨勫湴鍧� + autoCrop: boolean // 鏄惁榛樿鐢熸垚鎴浘妗� + autoCropWidth: number // 榛樿鐢熸垚鎴浘妗嗗搴� + autoCropHeight: number // 榛樿鐢熸垚鎴浘妗嗛珮搴� + fixedBox: boolean // 鍥哄畾鎴浘妗嗗ぇ灏� 涓嶅厑璁告敼鍙� + fileName: string + previews: any // 棰勮鏁版嵁 + outputType: string + visible: boolean } @@ -28,131 +83,76 @@ const cropper = ref<any>({}); //鍥剧墖瑁佸壀鏁版嵁 const options = reactive<Options>({ - img: userStore.avatar, - autoCrop: true, - autoCropWidth: 200, - autoCropHeight: 200, - fixedBox: true, - outputType: "png", - fileName: '', - previews: {}, - visible: false + img: userStore.avatar, + autoCrop: true, + autoCropWidth: 200, + autoCropHeight: 200, + fixedBox: true, + outputType: "png", + fileName: '', + previews: {}, + visible: false }); /** 缂栬緫澶村儚 */ const editCropper = () => { - open.value = true; + open.value = true; } /** 鎵撳紑寮瑰嚭灞傜粨鏉熸椂鐨勫洖璋� */ const modalOpened = () => { - visible.value = true; + visible.value = true; } /** 瑕嗙洊榛樿涓婁紶琛屼负 */ const requestUpload = (): any => {} /** 鍚戝乏鏃嬭浆 */ const rotateLeft = () => { - cropper.value.rotateLeft(); + cropper.value.rotateLeft(); } /** 鍚戝彸鏃嬭浆 */ const rotateRight = () => { - cropper.value.rotateRight(); + cropper.value.rotateRight(); } /** 鍥剧墖缂╂斁 */ const changeScale = (num: number) => { - num = num || 1; - cropper.value.changeScale(num); + num = num || 1; + cropper.value.changeScale(num); } /** 涓婁紶棰勫鐞� */ const beforeUpload = (file: 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; - }; - } + 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; + }; + } } /** 涓婁紶鍥剧墖 */ const uploadImg = async () => { - cropper.value.getCropBlob(async (data: any) => { - let formData = new FormData(); - formData.append("avatarfile", data, options.fileName); - const res = await uploadAvatar(formData); - open.value = false; - options.img = res.data.imgUrl; - userStore.avatar = options.img as string; - proxy?.$modal.msgSuccess("淇敼鎴愬姛"); - visible.value = false; - }); + cropper.value.getCropBlob(async (data: any) => { + let formData = new FormData(); + formData.append("avatarfile", data, options.fileName); + const res = await uploadAvatar(formData); + open.value = false; + options.img = res.data.imgUrl; + userStore.avatar = options.img as string; + proxy?.$modal.msgSuccess("淇敼鎴愬姛"); + visible.value = false; + }); } /** 瀹炴椂棰勮 */ const realTime = (data: any) => { - options.previews = data; + options.previews = data; } /** 鍏抽棴绐楀彛 */ const closeDialog = () => { - options.img = userStore.avatar; - options.visible = false; + options.img = userStore.avatar; + options.visible = false; } </script> - -<template> - <div class="user-info-head" @click="editCropper()"> - <img :src="options.img as string" title="鐐瑰嚮涓婁紶澶村儚" class="img-circle img-lg" /> - <el-dialog :title="title" v-model="open" width="800px" append-to-body @opened="modalOpened" @close="closeDialog"> - <el-row> - <el-col :xs="24" :md="12" :style="{ height: '350px' }"> - <vue-cropper - 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" - /> - </el-col> - <el-col :xs="24" :md="12" :style="{ height: '350px' }"> - <div class="avatar-upload-preview"> - <img :src="options.previews.url" :style="options.previews.img" /> - </div> - </el-col> - </el-row> - <br /> - <el-row> - <el-col :lg="2" :md="2"> - <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-button> - </el-upload> - </el-col> - <el-col :lg="{ span: 1, offset: 2 }" :md="2"> - <el-button icon="Plus" @click="changeScale(1)"></el-button> - </el-col> - <el-col :lg="{ span: 1, offset: 1 }" :md="2"> - <el-button icon="Minus" @click="changeScale(-1)"></el-button> - </el-col> - <el-col :lg="{ span: 1, offset: 1 }" :md="2"> - <el-button icon="RefreshLeft" @click="rotateLeft()"></el-button> - </el-col> - <el-col :lg="{ span: 1, offset: 1 }" :md="2"> - <el-button icon="RefreshRight" @click="rotateRight()"></el-button> - </el-col> - <el-col :lg="{ span: 2, offset: 6 }" :md="2"> - <el-button type="primary" @click="uploadImg()">鎻� 浜�</el-button> - </el-col> - </el-row> - </el-dialog> - </div> -</template> <style lang="scss" scoped> .user-info-head { -- Gitblit v1.9.3