|
@@ -1,5 +1,5 @@
|
1
|
1
|
<template>
|
2
|
|
- <div class="addPlayBtn-wrap" id="addPlayBtn-wrap">
|
|
2
|
+ <div class="addPlayBtn-wrap" id="addPlayBtn-wrap" v-loading="loading">
|
3
|
3
|
<div id="img-wrap"></div>
|
4
|
4
|
<div class="footer-wrap">
|
5
|
5
|
<el-button size="mini" @click="onClickCancel">取 消</el-button>
|
|
@@ -9,43 +9,37 @@
|
9
|
9
|
</template>
|
10
|
10
|
<script>
|
11
|
11
|
import axios from 'axios'
|
12
|
|
-import { imgToCanvas, canvasToImg, downloadCanves, drawPlaybtnToCanvasCenter, base64ToFile } from '@/assets/js/canvasTools.js'
|
|
12
|
+import { imgToCanvas, canvasToImg, drawPlaybtnToCanvasCenter, base64ToFile } from '@/assets/js/canvasTools.js'
|
13
|
13
|
|
14
|
14
|
export default {
|
15
|
|
- name: 'addPlaybtn',
|
16
|
|
- props:{
|
17
|
|
- fileUrl:{
|
18
|
|
- type: String
|
19
|
|
- },
|
20
|
|
- source: { // 涞源:默认是小程序图片裁剪,uploadMaterials来源于素材库裁剪
|
21
|
|
- type: String,
|
22
|
|
- default: 'applet'
|
23
|
|
- }
|
24
|
|
- },
|
25
|
|
- data() {
|
26
|
|
- return {
|
27
|
|
- loadCut: false,
|
28
|
|
- base64_url: '', // base64
|
29
|
|
- firstCome: true, // 判断是否初次进来
|
30
|
|
- oss_url: '', // 域名更新后的地址
|
31
|
|
- playbtn: require('../../assets/img/play-btn.png'),
|
32
|
|
- resImg: null,
|
33
|
|
- }
|
34
|
|
- },
|
35
|
|
- watch: {
|
36
|
|
- // target(){
|
37
|
|
- // this.target && this.target != '' && this.getBase64Image(this.target);
|
38
|
|
- // }
|
|
15
|
+ name: 'addPlaybtn',
|
|
16
|
+ props:{
|
|
17
|
+ fileUrl: {
|
|
18
|
+ type: String
|
39
|
19
|
},
|
40
|
|
- mounted(){
|
41
|
|
- // if(this.firstCome && this.target && this.target != ''){
|
42
|
|
- // this.getBase64Image (this.target)
|
43
|
|
- // }
|
44
|
|
- this.handler()
|
45
|
|
- },
|
46
|
|
- methods: {
|
47
|
|
- async handler() {
|
48
|
|
- console.log('handler => ')
|
|
20
|
+ source: { // 涞源:默认是小程序图片裁剪,uploadMaterials来源于素材库裁剪
|
|
21
|
+ type: String,
|
|
22
|
+ default: 'applet'
|
|
23
|
+ }
|
|
24
|
+ },
|
|
25
|
+ data() {
|
|
26
|
+ return {
|
|
27
|
+ base64_url: '', // base64
|
|
28
|
+ firstCome: true, // 判断是否初次进来
|
|
29
|
+ oss_url: '', // 域名更新后的地址
|
|
30
|
+ playbtn: require('../../assets/img/play-btn.png'),
|
|
31
|
+ resImg: null,
|
|
32
|
+ loading: false,
|
|
33
|
+ }
|
|
34
|
+ },
|
|
35
|
+ mounted(){
|
|
36
|
+ this.handler()
|
|
37
|
+ },
|
|
38
|
+ methods: {
|
|
39
|
+ async handler() {
|
|
40
|
+ console.log('handler => ')
|
|
41
|
+ try {
|
|
42
|
+ this.loading = true
|
49
|
43
|
// 1.图片路径转成canvas
|
50
|
44
|
let canvas = await imgToCanvas(this.fileUrl);
|
51
|
45
|
// 2. canvas添加水印
|
|
@@ -62,118 +56,44 @@ export default {
|
62
|
56
|
this.resImg = resImg
|
63
|
57
|
const wrap = document.getElementById('img-wrap')
|
64
|
58
|
wrap.appendChild(resImg.imageDom);
|
65
|
|
- },
|
66
|
|
- onClickCancel() {
|
67
|
|
- this.$emit('cancel')
|
68
|
|
- },
|
69
|
|
- onClickConfirm() {
|
70
|
|
- const file = base64ToFile(this.resImg.base64Data, 'base64转file生成的文件')
|
71
|
|
- let formData = new FormData();
|
72
|
|
- let axios_api = this.URL.material_upload;
|
73
|
|
- formData.append("type",1);
|
74
|
|
- formData.append("need_media_id",0);
|
75
|
|
- formData.append("admin_id",this.$cookie.getCookie('admin_id'));
|
76
|
|
- formData.append("ttl",this.$cookie.getCookie('ttl'));
|
77
|
|
- formData.append("sign",this.$cookie.getCookie('sign'));
|
78
|
|
- formData.append("corpid",this.$localSelfStore.getLocal('defaultCorp') && this.$localSelfStore.getLocal('defaultCorp') != 'undefined' ? JSON.parse(this.$localSelfStore.getLocal('defaultCorp')).corpid : '');
|
79
|
|
- formData.append("material_file", file);
|
80
|
|
-
|
81
|
|
- let instance= axios.create({
|
82
|
|
- baseURL: '',
|
83
|
|
- data: formData,
|
84
|
|
- headers: { 'Content-Type': 'multipart/form-data'}
|
85
|
|
- })
|
86
|
|
-
|
87
|
|
- instance.post(this.URL.BASEURL + axios_api, formData).then((res) => {
|
88
|
|
- var res = res.data
|
89
|
|
- if (res && res.errno == 0) {
|
90
|
|
- this.$emit('confirm', res.rst)
|
91
|
|
- } else if (res.errno != 4002) {
|
92
|
|
- this.$message({ message: res.err, type: "error" })
|
93
|
|
- }
|
94
|
|
- }).catch((err) => {
|
95
|
|
- this.$message({ message: '服务器错误,获取裁剪图片失败', type: "error" })
|
96
|
|
- });
|
97
|
|
- },
|
|
59
|
+ this.loading = false
|
|
60
|
+ } catch (error) {
|
|
61
|
+ this.loading = false
|
|
62
|
+ }
|
|
63
|
+ },
|
|
64
|
+ onClickCancel() {
|
|
65
|
+ this.$emit('cancel')
|
|
66
|
+ },
|
|
67
|
+ onClickConfirm() {
|
|
68
|
+ const file = base64ToFile(this.resImg.base64Data, 'base64转file生成的文件')
|
|
69
|
+ let formData = new FormData();
|
|
70
|
+ let axios_api = this.URL.material_upload;
|
|
71
|
+ formData.append("type",1);
|
|
72
|
+ formData.append("need_media_id",0);
|
|
73
|
+ formData.append("admin_id",this.$cookie.getCookie('admin_id'));
|
|
74
|
+ formData.append("ttl",this.$cookie.getCookie('ttl'));
|
|
75
|
+ formData.append("sign",this.$cookie.getCookie('sign'));
|
|
76
|
+ formData.append("corpid",this.$localSelfStore.getLocal('defaultCorp') && this.$localSelfStore.getLocal('defaultCorp') != 'undefined' ? JSON.parse(this.$localSelfStore.getLocal('defaultCorp')).corpid : '');
|
|
77
|
+ formData.append("material_file", file);
|
98
|
78
|
|
|
79
|
+ let instance= axios.create({
|
|
80
|
+ baseURL: '',
|
|
81
|
+ data: formData,
|
|
82
|
+ headers: { 'Content-Type': 'multipart/form-data'}
|
|
83
|
+ })
|
99
|
84
|
|
100
|
|
- getBase64Image (url, ref) {
|
101
|
|
- this.loadCut = true
|
102
|
|
- this.firstCome = false ;
|
103
|
|
- var that = this
|
104
|
|
- var image = new Image()
|
105
|
|
- image.src = url + '?v=' + Math.random() // 处理缓存
|
106
|
|
- image.crossOrigin = 'anonymous' // 支持跨域图片
|
107
|
|
- image.onload = function () {
|
108
|
|
- var base64 = that.drawBase64Image(image)
|
109
|
|
- that.loadCut = false;
|
110
|
|
- that.base64_url = base64;
|
111
|
|
- that.forIe9();
|
|
85
|
+ instance.post(this.URL.BASEURL + axios_api, formData).then((res) => {
|
|
86
|
+ var res = res.data
|
|
87
|
+ if (res && res.errno == 0) {
|
|
88
|
+ this.$emit('confirm', res.rst)
|
|
89
|
+ } else if (res.errno != 4002) {
|
|
90
|
+ this.$message({ message: res.err, type: "error" })
|
112
|
91
|
}
|
113
|
|
- },
|
114
|
|
- drawBase64Image (img) {
|
115
|
|
- var canvas = document.createElement('canvas')
|
116
|
|
- canvas.width = img.width
|
117
|
|
- canvas.height = img.height
|
118
|
|
- var ctx = canvas.getContext('2d')
|
119
|
|
- ctx.drawImage(img, 0, 0, img.width, img.height)
|
120
|
|
- var dataURL = canvas.toDataURL('image/png')
|
121
|
|
- return dataURL
|
122
|
|
- },
|
123
|
|
- //裁剪
|
124
|
|
- forIe9 () {
|
125
|
|
- this.$refs.imgCutterModal.handleOpen({
|
126
|
|
- name: 'img',
|
127
|
|
- src: this.base64_url,
|
128
|
|
- width: 400,
|
129
|
|
- height: 400,
|
130
|
|
- });
|
131
|
|
- },
|
132
|
|
- //通过cutDown事件接收选择的图片信息
|
133
|
|
- cutDown(event) {
|
134
|
|
- if (!event.file) {
|
135
|
|
- this.$emit('imgCutterCallback',{flag:false})
|
136
|
|
- this.$message({ message: '图片剪裁失败!', type: "error" })
|
137
|
|
- return
|
138
|
|
- };
|
139
|
|
- let formData = new FormData();
|
140
|
|
- let axios_api = this.URL.material_upload;
|
141
|
|
- formData.append("type",1);
|
142
|
|
- formData.append("need_media_id",0);
|
143
|
|
- formData.append("admin_id",this.$cookie.getCookie('admin_id'));
|
144
|
|
- formData.append("ttl",this.$cookie.getCookie('ttl'));
|
145
|
|
- formData.append("sign",this.$cookie.getCookie('sign'));
|
146
|
|
- formData.append("corpid",this.$localSelfStore.getLocal('defaultCorp') && this.$localSelfStore.getLocal('defaultCorp') != 'undefined' ? JSON.parse(this.$localSelfStore.getLocal('defaultCorp')).corpid : '');
|
147
|
|
-
|
148
|
|
- let instance= axios.create({
|
149
|
|
- baseURL: '',
|
150
|
|
- data: formData,
|
151
|
|
- headers: { 'Content-Type': 'multipart/form-data'}
|
152
|
|
- })
|
153
|
|
-
|
154
|
|
- if (this.source == 'uploadMaterials') { // 素材库
|
155
|
|
- formData.append("file",event.file);
|
156
|
|
- axios_api = this.URL.media_upload;
|
157
|
|
- } else {
|
158
|
|
- formData.append("material_file",event.file); //上传一个files对象
|
159
|
|
- }
|
160
|
|
-
|
161
|
|
- instance.post(this.URL.BASEURL + axios_api, formData).then((res) => {
|
162
|
|
- var res = res.data
|
163
|
|
- if (res && res.errno == 0) {
|
164
|
|
- this.$emit('imgCutterCallback',{flag:true,data:res.rst})
|
165
|
|
- } else if (res.errno != 4002) {
|
166
|
|
- this.$emit('imgCutterCallback',{flag:false})
|
167
|
|
- this.$message({ message: res.err, type: "error" })
|
168
|
|
- }
|
169
|
|
- }).catch((err) => {
|
170
|
|
- this.$emit('imgCutterCallback',{flag:false})
|
171
|
|
- this.$message({ message: '服务器错误,获取裁剪图片失败', type: "error" })
|
172
|
|
- });
|
173
|
|
-
|
174
|
|
- },
|
175
|
|
- }
|
176
|
|
-
|
|
92
|
+ }).catch((err) => {
|
|
93
|
+ this.$message({ message: '服务器错误,获取裁剪图片失败', type: "error" })
|
|
94
|
+ });
|
|
95
|
+ },
|
|
96
|
+ }
|
177
|
97
|
}
|
178
|
98
|
</script>
|
179
|
99
|
|