|
1 | 1 | <template>
|
2 |
| - <div |
3 |
| - v-show="value" |
4 |
| - class="vue-image-crop-upload" |
5 |
| - > |
6 |
| - <div class="vicp-wrap"> |
7 |
| - <img-upload |
8 |
| - v-model="show" |
9 |
| - field="img" |
10 |
| - :width="300" |
11 |
| - :height="300" |
12 |
| - url="https://httpbin.org/post" |
13 |
| - :params="params" |
14 |
| - :headers="headers" |
15 |
| - img-format="png" |
16 |
| - @crop-success="cropSuccess" |
17 |
| - @crop-upload-success="cropUploadSuccess" |
18 |
| - @crop-upload-fail="cropUploadFail" |
19 |
| - /> |
20 |
| - </div> |
21 |
| - </div> |
| 2 | + <image-crop-upload |
| 3 | + v-model="show" |
| 4 | + :field="field" |
| 5 | + :url="url" |
| 6 | + :width="width" |
| 7 | + :height="height" |
| 8 | + :params="params" |
| 9 | + :headers="headers" |
| 10 | + :lang-type="language" |
| 11 | + :with-credentials="true" |
| 12 | + img-format="png" |
| 13 | + @src-file-set="srcFileSet" |
| 14 | + @crop-success="cropSuccess" |
| 15 | + @crop-upload-success="cropUploadSuccess" |
| 16 | + @crop-upload-fail="cropUploadFail" |
| 17 | + /> |
22 | 18 | </template>
|
23 | 19 |
|
24 | 20 | <script lang="ts">
|
| 21 | +import ImageCropUpload from 'vue-image-crop-upload' |
25 | 22 | import { Component, Prop, Vue } from 'vue-property-decorator'
|
26 |
| -import imgUpload from 'vue-image-crop-upload' |
| 23 | +import { AppModule } from '@/store/modules/app' |
27 | 24 |
|
28 | 25 | @Component({
|
29 | 26 | name: 'AvatarUpload',
|
30 | 27 | components: {
|
31 |
| - imgUpload |
| 28 | + ImageCropUpload |
32 | 29 | }
|
33 | 30 | })
|
34 | 31 | export default class extends Vue {
|
35 |
| - @Prop({ default: true }) private value!: boolean |
| 32 | + // You can add more Prop, see: https://github.com/dai-siki/vue-image-crop-upload#usage |
| 33 | + @Prop({ required: true }) private value!: boolean |
| 34 | + @Prop({ required: true }) private url!: string |
| 35 | + @Prop({ required: true }) private field!: string |
| 36 | + @Prop({ default: 300 }) private width!: number |
| 37 | + @Prop({ default: 300 }) private height!: number |
| 38 | + @Prop({ default: () => {} }) private params!: object |
| 39 | + @Prop({ default: () => {} }) private headers!: object |
36 | 40 |
|
37 |
| - private customStyle!: Object |
38 |
| - private show = true |
39 |
| - private params = { token: '123456798', name: 'avatar' } |
40 |
| - private headers = { smail: '*_~' } |
41 |
| - private imgDataUrl = '' |
| 41 | + // https://github.com/dai-siki/vue-image-crop-upload#language-package |
| 42 | + private languageTypeList: { [key: string]: string } = { |
| 43 | + 'en': 'en', |
| 44 | + 'zh': 'zh', |
| 45 | + 'es': 'es-MX', |
| 46 | + 'ja': 'ja' |
| 47 | + } |
| 48 | +
|
| 49 | + get show() { |
| 50 | + return this.value |
| 51 | + } |
| 52 | +
|
| 53 | + set show(value) { |
| 54 | + this.$emit('input', value) |
| 55 | + } |
| 56 | +
|
| 57 | + get language() { |
| 58 | + return this.languageTypeList[AppModule.language] |
| 59 | + } |
42 | 60 |
|
43 |
| - private toggleShow() { |
44 |
| - this.show = !this.show |
| 61 | + private srcFileSet(fileName: string, fileType: string, fileSize: number) { |
| 62 | + this.$emit('src-file-set', fileName, fileType, fileSize) |
45 | 63 | }
|
46 | 64 |
|
47 | 65 | private cropSuccess(imgDataUrl: string, field: string) {
|
48 |
| - console.log('-------- crop success --------') |
49 |
| - this.imgDataUrl = imgDataUrl |
| 66 | + this.$emit('crop-success', imgDataUrl, field) |
50 | 67 | }
|
51 | 68 |
|
52 | 69 | private cropUploadSuccess(jsonData: any, field: string) {
|
53 |
| - console.log('-------- upload success --------') |
54 |
| - console.log(jsonData) |
55 |
| - this.$emit('crop-upload-success', jsonData.files.img) |
56 |
| - console.log('field: ' + field) |
| 70 | + this.$emit('crop-upload-success', jsonData, field) |
57 | 71 | }
|
58 | 72 |
|
59 | 73 | private cropUploadFail(status: boolean, field: string) {
|
60 |
| - console.log('-------- upload fail --------') |
61 |
| - console.log(status) |
62 |
| - console.log('field: ' + field) |
| 74 | + this.$emit('crop-upload-fail', status, field) |
63 | 75 | }
|
64 | 76 | }
|
65 | 77 | </script>
|
0 commit comments