RuoYi
2022-11-21 0effee74b176638329d6d378de44293219fd8de2
src/views/system/user/profile/userAvatar.vue
@@ -1,5 +1,6 @@
<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'}">
@@ -25,7 +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>
@@ -49,15 +55,16 @@
      </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);
@@ -78,27 +85,26 @@
/** 编辑头像 */
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) {
@@ -110,7 +116,7 @@
      options.img = reader.result;
    };
  }
};
}
/** 上传图片 */
function uploadImg() {
  proxy.$refs.cropper.getCropBlob(data => {
@@ -124,16 +130,16 @@
      visible.value = false;
    });
  });
};
}
/** 实时预览 */
function realTime(data) {
  options.previews = data;
};
}
/** 关闭窗口 */
function closeDialog() {
  options.img = userStore.avatar;
  options.visible = false;
};
}
</script>
<style lang='scss' scoped>