|
|
@@ -16,10 +16,19 @@
|
|
|
/>
|
|
|
|
|
|
<div class="btns">
|
|
|
- <van-button type="primary" plain @click="cancel">取消</van-button>
|
|
|
+ <van-button type="primary" plain @click="cancel(true)">取消</van-button>
|
|
|
<van-button type="primary" @click="getResult"> 确认</van-button>
|
|
|
</div>
|
|
|
</van-overlay>
|
|
|
+ <van-image-preview class="cropPreview" v-model:show="showPreview" :onClose="cancel" :images="imgs">
|
|
|
+ <template v-slot:cover>
|
|
|
+ <div class="btn-list" @click.stop="">
|
|
|
+ <van-button type="primary" plain @click="cancel(true)">取消</van-button>
|
|
|
+ <van-button v-if="!isGif" type="primary" plain @click="edit">编辑</van-button>
|
|
|
+ <van-button type="primary" @click="sure"> 确认</van-button>
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+ </van-image-preview>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
@@ -30,15 +39,48 @@ export default {
|
|
|
return {
|
|
|
show: false,
|
|
|
pic: '',
|
|
|
- result: {}
|
|
|
+ result: {},
|
|
|
+ imgs: [],
|
|
|
+ showPreview: false,
|
|
|
+ file: null,
|
|
|
+ next: false
|
|
|
};
|
|
|
},
|
|
|
+ computed: {
|
|
|
+ isGif() {
|
|
|
+ return this.file && this.file.file.type === 'image/gif';
|
|
|
+ }
|
|
|
+ },
|
|
|
methods: {
|
|
|
- init(img = '') {
|
|
|
+ init(img = '', file) {
|
|
|
this.pic = img;
|
|
|
+ this.imgs = [img];
|
|
|
+ this.file = file;
|
|
|
+ this.showPreview = true;
|
|
|
+ this.next = false;
|
|
|
+ },
|
|
|
+ edit() {
|
|
|
+ this.next = true;
|
|
|
+ this.showPreview = false;
|
|
|
this.show = true;
|
|
|
},
|
|
|
- cancel() {
|
|
|
+ sure() {
|
|
|
+ this.next = true;
|
|
|
+ this.$toast.loading({
|
|
|
+ message: '加载中...',
|
|
|
+ forbidClick: true
|
|
|
+ });
|
|
|
+ this.updateFile(this.file).then(img => {
|
|
|
+ this.$toast.clear();
|
|
|
+ this.showPreview = false;
|
|
|
+ this.$emit('updateImg', img);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ cancel(finish = false) {
|
|
|
+ if (this.next && finish !== true) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.showPreview = false;
|
|
|
this.show = false;
|
|
|
this.$emit('updateImg', '');
|
|
|
},
|
|
|
@@ -60,15 +102,20 @@ export default {
|
|
|
this.result.dataURL = base64;
|
|
|
this.result.blobURL = URL.createObjectURL(blob);
|
|
|
console.log(this.result);
|
|
|
- this.updateFile(base64).then(img => {
|
|
|
- this.$toast.clear();
|
|
|
- this.show = false;
|
|
|
- this.$emit('updateImg', img);
|
|
|
- });
|
|
|
+ this.updateFile2(base64)
|
|
|
+ .then(img => {
|
|
|
+ this.$toast.clear();
|
|
|
+ this.show = false;
|
|
|
+ this.$emit('updateImg', img);
|
|
|
+ })
|
|
|
+ .catch(e => {
|
|
|
+ this.$toast('图片太大,上传失败');
|
|
|
+ this.cancel(true);
|
|
|
+ });
|
|
|
// 隐藏裁切弹窗
|
|
|
// this.isShowDialog = false;
|
|
|
},
|
|
|
- updateFile(base64) {
|
|
|
+ updateFile2(base64) {
|
|
|
const formData = new FormData();
|
|
|
formData.append('base64', base64);
|
|
|
return http.axios.post('/upload/base64', formData).then(res => {
|
|
|
@@ -109,4 +156,22 @@ export default {
|
|
|
/deep/.cropper-point {
|
|
|
background-color: @prim;
|
|
|
}
|
|
|
+.btn-list {
|
|
|
+ .flex();
|
|
|
+ padding: 9px 16px;
|
|
|
+ justify-content: space-between;
|
|
|
+ .bottom(9px);
|
|
|
+ background-color: #222426;
|
|
|
+}
|
|
|
+</style>
|
|
|
+
|
|
|
+<style lang="less">
|
|
|
+.cropPreview {
|
|
|
+ .van-image-preview__cover {
|
|
|
+ z-index: 20;
|
|
|
+ bottom: 0;
|
|
|
+ top: auto;
|
|
|
+ right: 0;
|
|
|
+ }
|
|
|
+}
|
|
|
</style>
|