| ¶Ô±ÈÐÂÎļþ |
| | |
| | | <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-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>
|
| | | import "vue-cropper/dist/index.css"
|
| | | import { VueCropper } from "vue-cropper"
|
| | | import { uploadAvatar } from "@/api/system/user"
|
| | | import useUserStore from "@/store/modules/user"
|
| | |
|
| | | const userStore = useUserStore()
|
| | | const { proxy } = getCurrentInstance()
|
| | |
|
| | | const open = ref(false)
|
| | | const visible = ref(false)
|
| | | const title = ref("ä¿®æ¹å¤´å")
|
| | |
|
| | | //å¾çè£åªæ°æ®
|
| | | const options = reactive({
|
| | | img: userStore.avatar, // è£åªå¾ççå°å
|
| | | autoCrop: true, // æ¯å¦é»è®¤çææªå¾æ¡
|
| | | autoCropWidth: 200, // é»è®¤çææªå¾æ¡å®½åº¦
|
| | | autoCropHeight: 200, // é»è®¤çææªå¾æ¡é«åº¦
|
| | | fixedBox: true, // åºå®æªå¾æ¡å¤§å° ä¸å
许æ¹å
|
| | | outputType: "png", // é»è®¤çææªå¾ä¸ºPNGæ ¼å¼
|
| | | filename: 'avatar', // æä»¶åç§°
|
| | | previews: {} //é¢è§æ°æ®
|
| | | })
|
| | |
|
| | | /** ç¼è¾å¤´å */
|
| | | function editCropper() {
|
| | | open.value = true
|
| | | }
|
| | |
|
| | | /** æå¼å¼¹åºå±ç»ææ¶çåè° */
|
| | | function modalOpened() {
|
| | | visible.value = true
|
| | | }
|
| | |
|
| | | /** è¦çé»è®¤ä¸ä¼ è¡ä¸º */
|
| | | function requestUpload() { }
|
| | |
|
| | | /** åå·¦æè½¬ */
|
| | | function rotateLeft() {
|
| | | proxy.$refs.cropper.rotateLeft()
|
| | | }
|
| | |
|
| | | /** åå³æè½¬ */
|
| | | function rotateRight() {
|
| | | proxy.$refs.cropper.rotateRight()
|
| | | }
|
| | |
|
| | | /** å¾çç¼©æ¾ */
|
| | | function changeScale(num) {
|
| | | num = num || 1
|
| | | proxy.$refs.cropper.changeScale(num)
|
| | | }
|
| | |
|
| | | /** ä¸ä¼ é¢å¤ç */
|
| | | function beforeUpload(file) {
|
| | | if (file.type.indexOf("image/") == -1) {
|
| | | proxy.$modal.msgError("æä»¶æ ¼å¼é误ï¼è¯·ä¸ä¼ å¾çç±»å,å¦ï¼JPGï¼PNGåç¼çæä»¶ã")
|
| | | } else {
|
| | | const reader = new FileReader()
|
| | | reader.readAsDataURL(file)
|
| | | reader.onload = () => {
|
| | | options.img = reader.result
|
| | | options.filename = file.name
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | /** ä¸ä¼ å¾ç */
|
| | | function uploadImg() {
|
| | | proxy.$refs.cropper.getCropBlob(data => {
|
| | | let formData = new FormData()
|
| | | formData.append("avatarfile", data, options.filename)
|
| | | uploadAvatar(formData).then(response => {
|
| | | open.value = false
|
| | | options.img = import.meta.env.VITE_APP_BASE_API + '/profile/' + response.imgUrl
|
| | | userStore.avatar = options.img
|
| | | proxy.$modal.msgSuccess("ä¿®æ¹æå")
|
| | | visible.value = false
|
| | | })
|
| | | })
|
| | | }
|
| | |
|
| | | /** 宿¶é¢è§ */
|
| | | function realTime(data) {
|
| | | options.previews = data
|
| | | }
|
| | |
|
| | | /** å
³éçªå£ */
|
| | | function closeDialog() {
|
| | | options.img = userStore.avatar
|
| | | options.visible = false
|
| | | }
|
| | | </script>
|
| | |
|
| | | <style lang='scss' scoped>
|
| | | .user-info-head {
|
| | | position: relative;
|
| | | display: inline-block;
|
| | | height: 120px;
|
| | | }
|
| | |
|
| | | .user-info-head:hover:after {
|
| | | content: "+";
|
| | | position: absolute;
|
| | | left: 0;
|
| | | right: 0;
|
| | | top: 0;
|
| | | bottom: 0;
|
| | | color: #eee;
|
| | | background: rgba(0, 0, 0, 0.5);
|
| | | font-size: 24px;
|
| | | font-style: normal;
|
| | | -webkit-font-smoothing: antialiased;
|
| | | -moz-osx-font-smoothing: grayscale;
|
| | | cursor: pointer;
|
| | | line-height: 110px;
|
| | | border-radius: 50%;
|
| | | }
|
| | | </style> |