-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix(avatar-upload): make AvatarUpload component an wrapper for vue-im…
…age-crop-upload * Fix the bug that the background still showing when closed * Add more options for AvatarUpload component * Add docs and links for AvatarUpload component
- Loading branch information
Showing
4 changed files
with
121 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,77 @@ | ||
<template> | ||
<div | ||
v-show="value" | ||
class="vue-image-crop-upload" | ||
> | ||
<div class="vicp-wrap"> | ||
<img-upload | ||
v-model="show" | ||
field="img" | ||
:width="300" | ||
:height="300" | ||
url="https://httpbin.org/post" | ||
:params="params" | ||
:headers="headers" | ||
img-format="png" | ||
@crop-success="cropSuccess" | ||
@crop-upload-success="cropUploadSuccess" | ||
@crop-upload-fail="cropUploadFail" | ||
/> | ||
</div> | ||
</div> | ||
<image-crop-upload | ||
v-model="show" | ||
:field="field" | ||
:url="url" | ||
:width="width" | ||
:height="height" | ||
:params="params" | ||
:headers="headers" | ||
:lang-type="language" | ||
:with-credentials="true" | ||
img-format="png" | ||
@src-file-set="srcFileSet" | ||
@crop-success="cropSuccess" | ||
@crop-upload-success="cropUploadSuccess" | ||
@crop-upload-fail="cropUploadFail" | ||
/> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import ImageCropUpload from 'vue-image-crop-upload' | ||
import { Component, Prop, Vue } from 'vue-property-decorator' | ||
import imgUpload from 'vue-image-crop-upload' | ||
import { AppModule } from '@/store/modules/app' | ||
@Component({ | ||
name: 'AvatarUpload', | ||
components: { | ||
imgUpload | ||
ImageCropUpload | ||
} | ||
}) | ||
export default class extends Vue { | ||
@Prop({ default: true }) private value!: boolean | ||
// You can add more Prop, see: https://github.com/dai-siki/vue-image-crop-upload#usage | ||
@Prop({ required: true }) private value!: boolean | ||
@Prop({ required: true }) private url!: string | ||
@Prop({ required: true }) private field!: string | ||
@Prop({ default: 300 }) private width!: number | ||
@Prop({ default: 300 }) private height!: number | ||
@Prop({ default: () => {} }) private params!: object | ||
@Prop({ default: () => {} }) private headers!: object | ||
private customStyle!: Object | ||
private show = true | ||
private params = { token: '123456798', name: 'avatar' } | ||
private headers = { smail: '*_~' } | ||
private imgDataUrl = '' | ||
// https://github.com/dai-siki/vue-image-crop-upload#language-package | ||
private languageTypeList: { [key: string]: string } = { | ||
'en': 'en', | ||
'zh': 'zh', | ||
'es': 'es-MX', | ||
'ja': 'ja' | ||
} | ||
get show() { | ||
return this.value | ||
} | ||
set show(value) { | ||
this.$emit('input', value) | ||
} | ||
get language() { | ||
return this.languageTypeList[AppModule.language] | ||
} | ||
private toggleShow() { | ||
this.show = !this.show | ||
private srcFileSet(fileName: string, fileType: string, fileSize: number) { | ||
this.$emit('src-file-set', fileName, fileType, fileSize) | ||
} | ||
private cropSuccess(imgDataUrl: string, field: string) { | ||
console.log('-------- crop success --------') | ||
this.imgDataUrl = imgDataUrl | ||
this.$emit('crop-success', imgDataUrl, field) | ||
} | ||
private cropUploadSuccess(jsonData: any, field: string) { | ||
console.log('-------- upload success --------') | ||
console.log(jsonData) | ||
this.$emit('crop-upload-success', jsonData.files.img) | ||
console.log('field: ' + field) | ||
this.$emit('crop-upload-success', jsonData, field) | ||
} | ||
private cropUploadFail(status: boolean, field: string) { | ||
console.log('-------- upload fail --------') | ||
console.log(status) | ||
console.log('field: ' + field) | ||
this.$emit('crop-upload-fail', status, field) | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.