| | |
| | | <template>
|
| | | <div class="user-info-head" @click="editCropper()"><img :src="options.img" title="点击上传头像" class="img-circle img-lg" /></div>
|
| | | <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'}">
|
| | |
| | | <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-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'
|
| | | import useUserStore from "@/store/modules/user";
|
| | |
|
| | | const userStore = useUserStore()
|
| | | const userStore = useUserStore();
|
| | | const { proxy } = getCurrentInstance();
|
| | |
|
| | | const open = ref(false);
|
| | |
| | | /** 编辑头像 */
|
| | | function editCropper() {
|
| | | open.value = true;
|
| | | };
|
| | | }
|
| | | /** 打开弹出层结束时的回调 */
|
| | | function modalOpened() {
|
| | | visible.value = true;
|
| | | };
|
| | | }
|
| | | /** 覆盖默认上传行为 */
|
| | | function requestUpload() {
|
| | | };
|
| | | 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) {
|
| | |
| | | options.img = reader.result;
|
| | | };
|
| | | }
|
| | | };
|
| | | }
|
| | | /** 上传图片 */
|
| | | function uploadImg() {
|
| | | proxy.$refs.cropper.getCropBlob(data => {
|
| | |
| | | visible.value = false;
|
| | | });
|
| | | });
|
| | | };
|
| | | }
|
| | | /** 实时预览 */
|
| | | function realTime(data) {
|
| | | options.previews = data;
|
| | | };
|
| | | }
|
| | | /** 关闭窗口 */
|
| | | function closeDialog() {
|
| | | options.img = userStore.avatar;
|
| | | options.visible = false;
|
| | | };
|
| | | }
|
| | | </script>
|
| | |
|
| | | <style lang='scss' scoped>
|