publish.vue
9.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
<template>
<div class="containerbox">
<div class="flextwo sharetopk" @click="back">
<div class="leftrow leftrowkimg">
<img src="../../../assets/leftrow.png" alt />
</div>
<div class="sharemiddle">发布</div>
<div class="sharebtn">
<!-- <img src="../../../assets/sharebtn.png" alt /> -->
</div>
</div>
<div class="topcontainer">
<div class="publishitem flextwo" @click="selectkind">
<div class="publeft flexone">
<div class="kindname">
<span class="kindleft">分类</span>
{{ kindname }}
</div>
</div>
<img src="../../../assets/grayrow.png" alt class="yourow" />
</div>
<div class="enterkind">
<textarea name id cols="30" rows="10" placeholder="请输入您的想法" v-model="kindidea"></textarea>
</div>
<!-- <div @click="uppic">上传图片</div> -->
<div>
<van-uploader
v-model="fileList"
multiple="true"
:after-read="afterRead"
:max-count="9"
@delete="deleftimg"
/>
<!-- <div class="pubimg">
<img src="../../../assets/addpub.png" alt />
</div>-->
</div>
<div class="videoimgll">
<img src="../../../assets/upvideo.png" alt class="videoimgbtn" v-if="video_image==''" />
<img :src="video_image" alt v-else />
<div class="videoimgkk">
<input type="file" accept="video/*" @change="uploadfileone" />
</div>
<img src="../../../assets/anniu.png" alt class="listanniu" v-if="video_image!=''" />
</div>
<!-- <div class="pubimg"></div> -->
</div>
<van-loading type="spinner" color="#1989fa" v-if="cardzheng" />
<div class="kaishilu" @click="publish">发布</div>
<div class="pubpicker" v-if="showkind">
<van-picker
show-toolbar
:columns="columns"
@confirm="onConfirm"
@cancel="onCancel"
@setValues="getvalue"
/>
</div>
<!-- 发布成功 -->
<div class="register" v-if="success">
<div class="pubsuccess">
<div class="pubsuccessname">发布成功</div>
<div class="pubsure" @click="sure">确认</div>
</div>
</div>
</div>
</template>
<script>
import Vue from "vue";
import wx from "weixin-js-sdk";
import "vant/lib/index.css";
console.log(wx);
import { Picker, Uploader, Toast, Loading } from "vant";
Vue.use(Loading);
Vue.use(Picker);
Vue.use(Toast);
Vue.use(Uploader);
export default {
data() {
return {
columns: [],
showkind: false,
kindname: "请选择分类",
success: false,
kindidea: "",
fileList: [],
images: [],
chuanimage: [],
delimg: [],
sort: [],
sort_id: "",
chuanvideo: '',
showvideo: '',
video_image: '',
cardzheng: false
};
},
created() {
document.title = "唐元集公众号";
this.getkindlist();
},
methods: {
uppic() {
console.log(3378378);
wx.ready(() => {
wx.chooseImage({
count: 1,
sizeType: ["compressed"], // 可以指定是原图还是压缩图,默认二者都有
sourceType: ["album", "camera"], // 可以指定来源是相册还是相机,默认二者都有
success: function (res) {
var localIds = res.localIds; // 返回选定照片的本地ID列表,localId可以作为img标签的src属性显示图片
that.pic = localIds[0];
}
});
});
// 预览图片接;
// wx.uploadImage({
// localId: "", // 需要上传的图片的本地ID,由chooseImage接口获得
// isShowProgressTips: 1, // 默认为1,显示进度提示
// success: function(res) {
// var serverId = res.serverId; // 返回图片的服务器端ID
// }
// });
},
back() {
this.$router.go(-1);
},
selectkind() {
this.showkind = true;
},
onCancel() {
console.log(347344);
this.showkind = false;
},
onConfirm(value, index) {
console.log(78343784);
this.showkind = false;
this.kindname = value;
this.sort_id = this.sort[index].id;
},
sure() {
this.success = false;
},
// 上传图片
afterRead(file) {
let that = this;
console.log(file);
console.log(file.length);
that.cardzheng = true
if (file.length == undefined) {
var formdata = new FormData();
formdata.append("file", file.file);
that.delimg.push(file.file.name);
var url = "/api/common/upload";
that.$uploadFile
.post(url, formdata)
.then(function (res) {
console.log(res);
that.cardzheng = false;
let url = "http://tangyuanji.t.brotop.cn" + res.data.url;
that.images.push(url);
that.chuanimage.push(res.data.url);
})
.catch(err => {
console.log(err);
});
} else {
for (var i = 0; i < file.length; i++) {
console.log(file[i].file);
var formdata = new FormData();
formdata.append("file", file[i].file);
that.delimg.push(file[i].file.name);
var url = "/api/common/upload";
that.$uploadFile
.post(url, formdata)
.then(function (res) {
console.log(res);
that.cardzheng = false;
let url = "http://tangyuanji.t.brotop.cn" + res.data.url;
that.images.push(url);
that.chuanimage.push(res.data.url);
})
.catch(err => {
console.log(err);
that.cardzheng = false;
});
}
}
},
// 删除文件
deleftimg(e) {
let that = this;
let item = e.file.name;
this.delimg.forEach(function (value, index, array) {
if (value == item) {
that.delimg.splice(index, 1);
that.images.splice(index, 1);
that.chuanimage.splice(index, 1);
that.fileList.splice(index, 1)
}
});
this.delimg = this.delimg;
this.images = this.images;
this.chuanimage = this.chuanimage;
this.$forceUpdate();
},
// 上传视频
uploadfileone(e) {
let that = this;
that.cardzheng = true
console.log(e);
let file = e.target.files[0];
console.log(file);
var formdata = new FormData();
formdata.append("file", file);
// formdata.append("token", localStorage.getItem("token"));
var url = "/api/common/upload";
that.$uploadFile
.post(url, formdata)
.then(function (res) {
console.log(res);
that.cardzheng = false
that.chuanvideo = res.data.url;
that.showvideo = res.data.priview_url;
that.video_image = res.data.video_image
})
.catch(err => {
that.cardzheng = false
console.log(err);
});
},
// 获取分类列表
getkindlist() {
let that = this;
var url = "/api/social/sort";
let param = {};
that.$axios
.post(url, param)
.then(function (res) {
console.log(res);
let data = res.data;
data.forEach(function (value, index) {
that.columns.push(value.sort_name);
});
that.columns = that.columns;
that.sort = res.data;
})
.catch(function (err) {
console.log(err);
});
},
getvalue(value) {
console.log(value);
},
// 发布
publish() {
let that = this;
var url = "/api/social/send";
if (that.sort_id == "") {
Toast("请选择分类");
return false;
}
if (that.kindidea == "") {
Toast("请输入您的想法");
return false;
}
if (that.chuanimage.length != that.fileList.length) {
Toast("图片上传中");
return false;
}
if (that.chuanvideo == '' && that.cardzheng == true) {
Toast("视频上传中");
return false;
}
let param = {
sort_id: that.sort_id,
description: that.kindidea,
images: that.chuanimage.join(","),
video: that.chuanvideo
};
that.$axios
.post(url, param)
.then(function (res) {
console.log(res);
Toast("发布成功");
that.$router.go(-1);
})
.catch(function (err) {
console.log(err);
});
}
}
};
</script>
<style scoped>
@import "../../../style/society.css";
.van-loading {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 99;
}
.topcontainer {
padding: 0 0.32rem;
box-sizing: border-box;
background: #fff;
padding-bottom: 0.32rem;
box-sizing: border-box;
margin-top: 0.8rem;
}
.kindleft {
color: #323233;
font-size: 0.28rem;
margin-right: 0.32rem;
}
.videoimgkk {
width: 1.58rem;
height: 1.58rem;
position: absolute;
left: 0;
top: 0;
}
.videoimgll {
width: 1.58rem;
height: 1.58rem;
position: relative;
display: flex;
justify-content: center;
align-items: center;
border: 1px dashed #999;
}
.videoimgkk input {
width: 100%;
height: 100%;
outline: none;
border: none;
opacity: 0;
/* background: transparent;
outline: none;
border: none; */
}
.listanniu {
width: 0.5rem;
height: 0.5rem;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.videoimgbtn {
width: 0.8rem;
height: 0.8rem;
}
</style>