scorpio 2 years ago
parent
commit
0ff4145e17
5 changed files with 181 additions and 14 deletions
  1. 2 0
      package.json
  2. 6 1
      src/components/upload-office/index.vue
  3. 142 6
      src/views/dash/compoents/profile.vue
  4. 2 2
      src/views/task/index.vue
  5. 29 5
      yarn.lock

+ 2 - 0
package.json

@@ -25,6 +25,8 @@
     "vite-plugin-pages": "^0.25.0",
     "vite-plugin-vue-layouts": "^0.7.0",
     "vue": "^3.2.37",
+    "vue-advanced-cropper": "^2.8.8",
+    "vue-cropper": "^1.0.9",
     "vue-qr": "^4.0.9",
     "vue-router": "^4.1.2",
     "vue3-eventbus": "^2.0.0"

+ 6 - 1
src/components/upload-office/index.vue

@@ -21,7 +21,7 @@
         class="padding-left padding-right radius-5 white grey-9-bg ml-5"
       ></div>
     </div>
-    <div class="upload" v-if="drawer">
+    <div class="upload" v-if="drawer && showProgress">
       <div>
         <div class="full-width flex flex-justify-end">
           <el-icon @click="drawer = false">
@@ -59,6 +59,10 @@ export default {
       type: String,
       default: '.pdf, .doc,.docx,.ppt, .pptx, .xls, .xlsx,.PDF'
     },
+    showProgress: {
+      type: Boolean,
+      default: true
+    },
     max: {
       type: Number,
       default: 9
@@ -90,6 +94,7 @@ export default {
     success(res) {
       if (res.code === 200) {
         this.resultList.push(res.data)
+        this.$emit('upload', this.resultList)
       }
       if (this.resultList.length === this.fileList.length) {
         this.saveLibrary()

+ 142 - 6
src/views/dash/compoents/profile.vue

@@ -2,8 +2,11 @@
   <div class="full-width flex">
     <div class="flex flex-col flex-justify-around flex-center full-height">
       <div class="bold font-16" style="margin-top: -10px">我的信息</div>
-      <div class="mt-10 ml-20">
+      <div class="mt-10 ml-20" @click="show = true">
         <el-avatar :src="user.info.avatarUrl" :size="100"></el-avatar>
+        <el-icon :size="25" style="margin-left: -30px">
+          <EditPen />
+        </el-icon>
       </div>
       <div class="mt-10" style="margin-left: 33px">
         {{ user.info.nickName }}
@@ -23,26 +26,108 @@
       <div
         class="flex flex-center flex-justify-between mt-10 padding-left padding-right"
       >
-        <img
+        <el-tooltip
           v-for="icon in icons"
           :key="icon.value"
-          :src="icon.icon"
-          class="icon-task"
-          @click="changeWorkStatus(icon)"
-        />
+          :content="icon.tips"
+        >
+          <img
+            :src="icon.icon"
+            class="icon-task pointer"
+            @click="changeWorkStatus(icon)"
+          />
+        </el-tooltip>
       </div>
     </div>
+
+    <el-dialog title="修改头像" v-model="show" width="780px">
+      <div>
+        <div>
+          <span
+            class="full-width text-left flex flex-justify-start padding-top padding-bottom"
+          >
+            新头像不允许涉及政治敏感与色情;<br />
+            图片格式必须为:png,jpeg,jpg;不可大于2M;<br />
+            建议使用png格式图片,以保持最佳效果;建议图片尺寸为144px*144px
+          </span>
+          <div class="flex flex-justify-start padding-bottom">
+            <upload-office
+              accept=".jpg,.png,.jpeg"
+              :max="1"
+              :show-progress="false"
+              @upload="upload"
+            />
+          </div>
+        </div>
+        <el-divider />
+        <div class="flex flex-justify-start">
+          <div class="ml-20 flex flex-justify-start flex-col">
+            <div class="bold text-left">头像裁剪</div>
+            <div class="mt-20 upload flex flex-center">
+              <cropper
+                ref="cropper"
+                class="cropper"
+                :src="img"
+                :stencil-props="{
+                  aspectRatio: 1 / 1,
+                  resizable: false
+                }"
+                @change="changeAvatar"
+              ></cropper>
+            </div>
+          </div>
+          <div class="ml-20 flex flex-justify-start flex-col">
+            <div class="bold text-left">头像预览</div>
+            <div class="mt-20 preview flex flex-center">
+              <el-avatar
+                v-if="previewImg"
+                :size="114"
+                fit="fill"
+                :src="previewImg"
+              ></el-avatar>
+
+              <el-avatar
+                v-if="previewImg"
+                :size="114"
+                shape="square"
+                fit="fill"
+                class="ml-20"
+                :src="previewImg"
+              ></el-avatar>
+            </div>
+          </div>
+        </div>
+        <div class="mt-20 full-width flex flex-justify-end">
+          <el-button type="primary" plain @click="show = false"
+            >取 消</el-button
+          >
+          <el-button type="primary" @click="uploadImage">确 定</el-button>
+        </div>
+      </div>
+    </el-dialog>
   </div>
 </template>
 
 <script>
 import { useStore } from '@/store/user.js'
+import { Cropper } from 'vue-advanced-cropper'
+import 'vue-advanced-cropper/dist/style.css'
+import api from '@/api/index.js'
+import website from '@/config/website.js'
+import { getToken } from '@/utils/auth.js'
+import { Base64 } from 'js-base64'
+import uploadOffice from '@/components/upload-office/index.vue'
 
 export default {
+  components: {
+    Cropper,
+    uploadOffice
+  },
   setup() {
     const user = useStore()
     return { user }
   },
+
   watch: {
     status: {
       handler(val) {
@@ -57,9 +142,18 @@ export default {
   },
   data() {
     return {
+      show: false,
       status: '',
+      img: '',
+      previewImg: '',
       placeholder: '请填写状态(最长6个字符)',
       id: '',
+      headers: {
+        Authorization: `Basic ${Base64.encode(
+          `${website.clientId}:${website.clientSecret}`
+        )}`,
+        'Blade-Auth': 'bearer ' + getToken()
+      },
       icons: [
         {
           icon: new URL('../../../assets/svg/task/work.svg', import.meta.url)
@@ -120,18 +214,60 @@ export default {
     },
     changeWorkStatus(res) {
       this.status = res.tips
+    },
+    upload(list) {
+      this.previewImg = list[0].filePath
+      this.img = list[0].filePath
+    },
+    changeAvatar({ coordinates, image, canvas }) {
+      this.previewImg = canvas.toDataURL()
+    },
+    uploadImage() {
+      const { canvas } = this.$refs.cropper.getResult()
+      if (canvas) {
+        const form = new FormData()
+        canvas.toBlob(blob => {
+          form.append('file', blob)
+          // You can use axios, superagent and other libraries instead here
+          fetch(api.uploadPath, {
+            method: 'POST',
+            headers: this.headers,
+            body: form
+          })
+          // Perhaps you should add the setting appropriate file format here
+        }, 'image/jpeg')
+      }
     }
   }
 }
 </script>
 
 <style lang="scss" scoped>
+.preview {
+  background-color: #eeeeee;
+  height: 240px;
+  width: 360px;
+  border-radius: 8px;
+}
+
+.upload {
+  background-color: #eeeeee;
+  height: 240px;
+  width: 320px;
+  border-radius: 8px;
+}
+
 .icon-task {
   width: 38px;
   height: 45px;
   object-fit: fill;
 }
 
+.cropper {
+  width: 280px;
+  height: 280px;
+}
+
 .input {
   height: 100px;
 

+ 2 - 2
src/views/task/index.vue

@@ -29,7 +29,7 @@
       <div class="full-width flex flex-justify-start">
         <el-dropdown @command="dropDown">
           <span class="flex flex-center">
-            {{ isGroup === 0 ? '按时间排序' : '按项目排序' }}
+            {{ isGroup === '0' ? '按时间排序' : '按项目排序' }}
             <el-icon class="el-icon--right">
               <arrow-down />
             </el-icon>
@@ -93,7 +93,7 @@ export default {
       task: [],
       taskId: '',
       total: 0,
-      isGroup: 0,
+      isGroup: '0',
       option: {
         showCheckBox: false,
         folderChecked: true,

+ 29 - 5
yarn.lock

@@ -927,6 +927,11 @@ cidr-regex@^3.1.1:
   dependencies:
     ip-regex "^4.1.0"
 
+classnames@^2.2.6:
+  version "2.3.2"
+  resolved "https://registry.yarnpkg.com/classnames/-/classnames-2.3.2.tgz#351d813bf0137fcc6a76a16b88208d2560a0d924"
+  integrity sha512-CSbhY4cFEJRe6/GQzIk5qXZ4Jeg5pcsP7b5peFSDpffpe1cqjASH/n9UTjBwOp6XpMSTwQ8Za2K5V02ueA7Tmw==
+
 clean-stack@^2.0.0:
   version "2.2.0"
   resolved "https://registry.yarnpkg.com/clean-stack/-/clean-stack-2.2.0.tgz#ee8472dbb129e727b31e8a10a427dee9dfe4008b"
@@ -1059,6 +1064,11 @@ dayjs@^1.10.4, dayjs@^1.11.3:
   resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.11.8.tgz#4282f139c8c19dd6d0c7bd571e30c2d0ba7698ea"
   integrity sha512-LcgxzFoWMEPO7ggRv1Y2N31hUf2R0Vj7fuy/m+Bg1K8rr+KAs1AEy4y9jd5DXe8pbHgX+srkHNS7TH6Q6ZhYeQ==
 
+debounce@^1.2.0:
+  version "1.2.1"
+  resolved "https://registry.yarnpkg.com/debounce/-/debounce-1.2.1.tgz#38881d8f4166a5c5848020c11827b834bcb3e0a5"
+  integrity sha512-XRRe6Glud4rd/ZGQfiV1ruXSfbvfJedlV9Y6zOlP+2K04vBYiJEte6stfFkCP03aMnY5tsipamumUjL14fofug==
+
 debug@4, debug@^4.1.0, debug@^4.1.1, debug@^4.3.2, debug@^4.3.3, debug@^4.3.4:
   version "4.3.4"
   resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865"
@@ -1188,6 +1198,11 @@ eastasianwidth@^0.2.0:
   resolved "https://registry.yarnpkg.com/eastasianwidth/-/eastasianwidth-0.2.0.tgz#696ce2ec0aa0e6ea93a397ffcf24aa7840c827cb"
   integrity sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==
 
+easy-bem@^1.0.2:
+  version "1.1.1"
+  resolved "https://registry.yarnpkg.com/easy-bem/-/easy-bem-1.1.1.tgz#1bfcc10425498090bcfddc0f9c000aba91399e03"
+  integrity sha512-GJRqdiy2h+EXy6a8E6R+ubmqUM08BK0FWNq41k24fup6045biQ8NXxoXimiwegMQvFFV3t1emADdGNL1TlS61A==
+
 echarts@^5.4.1:
   version "5.4.2"
   resolved "https://registry.yarnpkg.com/echarts/-/echarts-5.4.2.tgz#9f38781c9c6ae323e896956178f6956952c77a48"
@@ -4032,6 +4047,20 @@ vite@^3.0.0:
   optionalDependencies:
     fsevents "~2.3.2"
 
+vue-advanced-cropper@^2.8.8:
+  version "2.8.8"
+  resolved "https://registry.yarnpkg.com/vue-advanced-cropper/-/vue-advanced-cropper-2.8.8.tgz#af0e8324312be5a1a92ce9fd3aff8264d28a5b33"
+  integrity sha512-yDM7Jb/gnxcs//JdbOogBUoHr1bhCQSto7/ohgETKAe4wvRpmqIkKSppMm1huVQr+GP1YoVlX/fkjKxvYzwwDQ==
+  dependencies:
+    classnames "^2.2.6"
+    debounce "^1.2.0"
+    easy-bem "^1.0.2"
+
+vue-cropper@^1.0.9:
+  version "1.0.9"
+  resolved "https://registry.yarnpkg.com/vue-cropper/-/vue-cropper-1.0.9.tgz#de402c57cadc221e9a2063399ff35bb04220ef22"
+  integrity sha512-JhQwxmjqmQohzI7sAp5O/Rfdxuw5HOEYkKjnp/De7iCi6c8Mv6M3N9HpMt9xgWCFchX3/DfXBv2axCZOCg3G8Q==
+
 vue-demi@*, vue-demi@>=0.14.5:
   version "0.14.5"
   resolved "https://registry.yarnpkg.com/vue-demi/-/vue-demi-0.14.5.tgz#676d0463d1a1266d5ab5cba932e043d8f5f2fbd9"
@@ -4063,11 +4092,6 @@ vue-eslint-parser@^9.3.0:
     lodash "^4.17.21"
     semver "^7.3.6"
 
-vue-infinite-auto-scroll@^1.2.1:
-  version "1.2.1"
-  resolved "https://registry.yarnpkg.com/vue-infinite-auto-scroll/-/vue-infinite-auto-scroll-1.2.1.tgz#6e498670cdbe0840dfe5b216073726d4d7f6e47f"
-  integrity sha512-2olo5FfDXDe+CjJH0SjTz4Y7Rlo3vm4BfxBL+jp88OpjC09rbLE/xLyC1xr7hUHTlfIiHBLrHDYcNoG1u7WofQ==
-
 vue-qr@^4.0.9:
   version "4.0.9"
   resolved "https://registry.yarnpkg.com/vue-qr/-/vue-qr-4.0.9.tgz#6cb965dd0c5a0dff947e6ef582ef149b0780b986"