addtalk.html
6.1 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="divport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
<title>发动态</title>
<link rel="stylesheet" href="__TMPL__/public/assets/css/init.css">
<link rel="stylesheet" href="__TMPL__/public/assets/css/swiper-3.4.2.min.css">
<link rel="stylesheet" href="http://at.alicdn.com/t/font_793738_etrccfh2qxm.css">
<link rel="stylesheet" href="__TMPL__/public/assets/css/diseaseColumn.css">
<link rel="stylesheet" href="__TMPL__/public/assets/css/ChatCircle.css">
<link rel="stylesheet" href="__TMPL__/public/assets/css/chat.css">
<link rel="stylesheet" href="__TMPL__/public/assets/css/weui.css">
<link rel="stylesheet" href="__TMPL__/public/assets/css/myweui.css">
<script src="__TMPL__/public/assets/js/fontsize.js"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
</head>
<body>
<div class='box'>
<div class='textarea_box'>
<textarea class='textarea' placeholder=''></textarea>
</div>
<div class="weui-uploader">
<div class="weui-uploader__hd">
<p class="title">上传图片(最多九张)</p>
</div>
<div class="weui-uploader__bd">
<ul class="weui-uploader__files" id="uploaderFiles">
</ul>
<div class="weui-uploader__input-box addpic">
<!--<input id="uploaderInput" class="weui-uploader__input" type="file" accept="image/*" multiple/>-->
</div>
</div>
</div>
</div>
<!--dibu-->
<div class="null_box"></div>
<div class="submit_btn">发布</div>
<script src="__TMPL__/public/assets/js/jquery-2.1.0.js"></script>
<script src="__TMPL__/public/assets/js/weui.js"></script>
<script src="__TMPL__/public/assets/js/myweui.js"></script>
<!--<script>
$(function () {
var tmpl = '<li class="weui-uploader__file" style="background-image:url(#url#)"></li>',
$gallery = $("#gallery"), $galleryImg = $("#galleryImg"),
$uploaderInput = $("#uploaderInput"),
$uploaderFiles = $("#uploaderFiles");
$uploaderInput.on("change", function (e) {
var src, url = window.URL || window.webkitURL || window.mozURL, files = e.target.files;
for (var i = 0, len = files.length; i < len; ++i) {
var file = files[i];
console.log(file);
if (url) {
src = url.createObjectURL(file);
} else {
src = e.target.result;
}
console.log(src);
$uploaderFiles.append($(tmpl.replace('#url#', src)));
}
});
$uploaderFiles.on("click", "li", function () {
$galleryImg.attr("style", this.getAttribute("style"));
$gallery.fadeIn(100);
});
$gallery.on("click", function () {
$gallery.fadeOut(100);
});
});
$('.submit_btn').on('click',function (e) {
/*获取页面的所有信息*/
var textinfo=$('textarea').val();
console.log(textinfo);
})
</script>-->
<script type="application/javascript">
var serverIds = '';
wx.config({$sdk});
$('.addpic').on('click',function (res) {
console.log(11111);
var length = $('.length').length;
if(length>=9){
alert('不能上传了')
$('#addpic').hide();
return false;
}
wx.chooseImage({
count: 9-length, // 默认9
sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
success: function (res) {
// alert(res.localIds);
// alert(res.localIds.length);
console.log(res.localIds);
console.log(1111111111);
for(var i=0;i<res.localIds.length;i++){
// $('.addpic').before('<img style="width:100px;height:100px;" class="length" src="'+res.localIds[i]+'"/>')
$('.addpic').before('<li class="weui-uploader__file length" src="'+res.localIds[i]+'" style="background-image:url('+res.localIds[i]+')"></li>')
}
uploadImages(res.localIds)// 返回选定照片的本地ID列表,localId可以作为img标签的src属性显示图片
}
});
})
function uploadImages(localIds) {
var localId = localIds.pop();
wx.uploadImage({
localId: localId,
isShowProgressTips: 1,
success: function (res) {
var serverId = res.serverId; // 返回图片的服务器端ID
console.log(serverId);
serverIds += serverId + ',';
if (localIds.length > 0) {
uploadImages(localIds);
}
},
fail: function (res) {
$modal.toast(JSON.stringify(res));
}
});
}
$('.submit_btn').on('click',function (e) {
/*获取页面的所有信息*/
var textinfo=$('textarea').val();
if (!textinfo){
alert('内容不能为空');
return;
}
var picture=new Array()
var length = $('.length').length;
console.log(length);
for(var i=0;i<length;i++){
picture[i]=$('.length').eq(i).attr('src');
}
console.log(i);
console.log(picture);
$.ajax({
url: "{:url('addPost')}",
type: "post",
num:i,
data: {
group_id:{$group_id},
'num':i,
'post_content': textinfo,
'media': serverIds
},
success: function (data) {
if (data==1){
alert('发布成功!增加{$firend}积分');
window.location.href='{:url('index')}'
} else {
alert('发布失败!');
}
}
})
})
</script>
</body>
</html>