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
// pages/circleNoticeNew/circleNoticeNew.js
import Notify from '../../dist/notify/notify';
var app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
circleId: '',
circleDat: null,
title: '',
comment:'',
fileList: [],
imagePath:'',
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
//获取参数
this.setData({
circleId: options.circleId
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
},
//第1张图片
delete(event) {
const { index, name } = event.detail;
const fileList = this.data[`fileList`];
fileList.splice(index, 1);
this.setData({ [`fileList`]: fileList });
},
afterRead(event) {
const { file, name } = event.detail;
const fileList = this.data[`fileList`];
this.setData({
[`fileList`]: fileList.concat(file),
imagePath: file[0].path
});
},
beforeRead(event) {
const { file, callback } = event.detail;
if (file[0].path.indexOf('jpg') < 0) {
wx.showToast({ title: '请选择jpg图片上传', icon: 'none' });
callback(false);
return;
}
callback(true);
},
//发布公告
publish(){
var that = this;
//内容必须输入
if (that.data.title == null || that.data.title.trim() == "") {
Notify('请输入公告标题')
return
}
//内容必须输入
if (that.data.comment == null || that.data.comment.trim() == "") {
Notify('请输入公告内容')
return
}
var config = wx.getStorageSync('config');
wx.request({
url: app.url + 'ajax_set_circle_notice_new.php',
data: {
unionId: config.unionId,
circleId: that.data.circleId,
title: that.data.title,
comment: that.data.comment,
},
header: { 'content-type': 'application/json' },
method: 'GET',
dataType: 'json',
success: function (res) {
if (that.data.imagePath != null && that.data.imagePath != undefined) {
wx.uploadFile({
url: app.url + 'ajax_set_circle_notice_new.php?unionId=' + config.unionId + "&circleId=" + that.data.circleId,
filePath: that.data.imagePath,
name: 'image',
header: { 'content-type': 'multipart/form-data' },
success: function (res) {
Notify('发布成功!')
//循环执行等待全部结束
var a = setInterval(function () {
//跳转到圈子首页
wx.redirectTo({
url: '../circleDetails/circleDetails?circleId=' + that.data.circleId,
});
//循环执行代码
clearInterval(a)
}, 1000) //循环时间 这里是1秒
},
fail: function (res) {
console.log(res, '上传失败')
},
complete: function (res) {
},
})
}
},
fail: function (res) { },
complete: function (res) { },
})
},
//获取输入的公告标题
inputTitle(event){
this.setData({
title: event.detail.value
})
},
//获取输入的公告内容
inputComment(event) {
this.setData({
comment: event.detail.value
})
}
})