Skip to content

Commit 697d856

Browse files
committed
Initialize the database
1 parent effaf88 commit 697d856

17 files changed

+543
-212
lines changed

app.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
//app.js
22
App({
33
onLaunch: function () {
4+
//初始化云开发
5+
wx.cloud.init({
6+
env: "holotask-1gb3a2qhe28a3262"
7+
})
8+
//获取openid
9+
wx.cloud.callFunction({
10+
name: 'getOpenid',
11+
complete: res => {
12+
this.globalData.openid = res.result.openid
13+
this.globalData.appid = res.result.appid
14+
}
15+
})
416
// 获取用户信息
517
wx.getSetting({
618
success: res => {
@@ -24,16 +36,14 @@ App({
2436
//获取夜间模式
2537
wx.getSystemInfo({
2638
success: (res) => {
27-
this.globalData.is_dark = res.theme;
39+
this.globalData.theme = res.theme;
2840
}
2941
})
30-
//初始化云开发
31-
wx.cloud.init({
32-
env: "holotask-1gb3a2qhe28a3262"
33-
})
3442
},
3543
globalData: {
3644
userInfo: null,
37-
is_dark: null
45+
theme: null,
46+
openid: null,
47+
appid: null
3848
}
3949
})

pages/add/add.js

Lines changed: 183 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,52 @@
11
// pages/add/add.js
2+
const app = getApp()
3+
var util = require("../../utils/util.js")
24
Page({
35

46
/**
57
* 页面的初始数据
68
*/
79
data: {
10+
openid: null,
11+
theme: null,
12+
array: null,
13+
nickname: null,
814
input: [{
915
main: "",
1016
placeholder: "",
11-
number: 0
17+
number: 0,
18+
helptext: "任务标题",
19+
helptext_style: ""
1220
}, {
1321
main: "",
1422
placeholder: "",
15-
number: 0
23+
number: 0,
24+
helptext: "任务发布者,留空默认为自己"
1625
}, {
1726
main: "",
1827
placeholder: "",
19-
number: 0
28+
number: 0,
29+
helptext: "任务详细内容,支持换行",
30+
helptext_style: ""
2031
}],
2132
picker: [{
2233
main: "",
2334
placeholder: "",
24-
value: "."
35+
value: ".",
36+
helptext: "任务对象,可选择自己或管理的群组",
37+
helptext_style: ""
2538
}, {
2639
main: "",
2740
placeholder: "",
28-
value: "."
41+
value: ".",
42+
helptext: "任务截止日期",
43+
helptext_style: ""
44+
}, {
45+
main: "",
46+
placeholder: "",
47+
value: ".",
48+
helptext: "任务截止时间",
49+
helptext_style: ""
2950
}],
3051
},
3152
input: function (e) {
@@ -39,9 +60,13 @@ Page({
3960
let id = e.currentTarget.dataset.id
4061
let str1 = "input[" + id + "].main"
4162
let str2 = "input[" + id + "].placeholder"
63+
let str3 = "input[" + id + "].helptext"
64+
let str4 = "input[" + id + "].helptext_style"
4265
this.setData({
4366
[str1]: "border-bottom: 1.5px solid #07c160;",
4467
[str2]: "font-size:0.7rem;color:#07c160;top:0rpx;",
68+
[str3]: e.currentTarget.dataset.helptext,
69+
[str4]: "color:#666;"
4570
})
4671
},
4772

@@ -62,23 +87,172 @@ Page({
6287
},
6388

6489
change: function (e) {
65-
console.log(e.detail.value)
6690
let id = e.currentTarget.dataset.id
6791
let str1 = "picker[" + id + "].value"
6892
let str2 = "picker[" + id + "].placeholder"
69-
let str3 = "picker[" + id + "].opacity"
93+
let str3 = "picker[" + id + "].style"
94+
let str4 = "picker[" + id + "].helptext"
95+
let str5 = "picker[" + id + "].helptext_style"
7096
this.setData({
7197
[str1]: e.detail.value,
7298
[str2]: "font-size:0.7rem;color:#666;top:0rpx;",
73-
[str3]: "opacity:1"
99+
[str3]: "opacity:1",
100+
[str4]: e.currentTarget.dataset.helptext,
101+
[str5]: "color:#666;"
102+
})
103+
},
104+
105+
nchange: function (e) {
106+
// console.log(e)
107+
let str1 = "picker[0].value"
108+
let str2 = "picker[0].placeholder"
109+
let str3 = "picker[0].style"
110+
let str4 = "picker[0].helptext"
111+
let str5 = "picker[0].helptext_style"
112+
this.setData({
113+
[str1]: this.data.array[e.detail.value].name,
114+
[str2]: "font-size:0.7rem;color:#666;top:0rpx;",
115+
[str3]: "opacity:1",
116+
[str4]: e.currentTarget.dataset.helptext,
117+
[str5]: "color:#666;"
118+
})
119+
},
120+
121+
reset: function (e) {
122+
let str1 = "picker[0].value"
123+
let str2 = "picker[1].value"
124+
let str3 = "picker[2].value"
125+
let str4 = "picker[0].style"
126+
let str5 = "picker[1].style"
127+
let str6 = "picker[2].style"
128+
let str7 = "picker[0].placeholder"
129+
let str8 = "picker[1].placeholder"
130+
let str9 = "picker[2].placeholder"
131+
this.setData({
132+
[str1]: '.',
133+
[str2]: '.',
134+
[str3]: '.',
135+
[str4]: "opacity:0;",
136+
[str5]: "opacity:0;",
137+
[str6]: "opacity:0;",
138+
[str7]: "font-size:1rem;color:#666;top:40rpx;",
139+
[str8]: "font-size:1rem;color:#666;top:40rpx;",
140+
[str9]: "font-size:1rem;color:#666;top:40rpx;"
74141
})
75142
},
76143

144+
submit: function (e) {
145+
// console.log(e)
146+
if (e.detail.value.groupid == "") {
147+
this.setData({
148+
["picker[0].helptext"]: "此项不得为空",
149+
["picker[0].helptext_style"]: "color:#ff8a80;"
150+
})
151+
}
152+
if (e.detail.value.title == "") {
153+
this.setData({
154+
["input[0].helptext"]: "此项不得为空",
155+
["input[0].helptext_style"]: "color:#ff8a80;"
156+
})
157+
}
158+
if (e.detail.value.date == "") {
159+
this.setData({
160+
["picker[1].helptext"]: "此项不得为空",
161+
["picker[1].helptext_style"]: "color:#ff8a80;"
162+
})
163+
}
164+
if (e.detail.value.time == "") {
165+
this.setData({
166+
["picker[2].helptext"]: "此项不得为空",
167+
["picker[2].helptext_style"]: "color:#ff8a80;"
168+
})
169+
}
170+
if (e.detail.value.content == "") {
171+
this.setData({
172+
["input[2].helptext"]: "此项不得为空",
173+
["input[2].helptext_style"]: "color:#ff8a80;"
174+
})
175+
}
176+
177+
if (e.detail.value.groupid != "" && e.detail.value.title != "" && e.detail.value.date != "" && e.detail.value.time != "" && e.detail.value.content != "") {
178+
console.log("success")
179+
console.log(this.data.nickname)
180+
let time = e.detail.value.date + " " + e.detail.value.time
181+
let admin = (e.detail.value.admin) ? (e.detail.value.admin) : (this.data.nickname)
182+
wx.cloud.database().collection('data').add({
183+
data: {
184+
groupid: e.detail.value.groupid,
185+
title: e.detail.value.title,
186+
admin: admin,
187+
timestamp: Date.parse(time.replace(/-/g, '/')),
188+
content: e.detail.value.content,
189+
finished: false
190+
}
191+
})
192+
wx.showToast({
193+
title: "任务已发布",
194+
duration: 500
195+
})
196+
}
197+
},
198+
77199
/**
78200
* 生命周期函数--监听页面加载
79201
*/
80202
onLoad: function (options) {
81-
203+
//获取openid
204+
if (app.globalData.openid) {
205+
this.setData({
206+
openid: app.globalData.openid
207+
})
208+
} else {
209+
wx.cloud.callFunction({
210+
name: 'getOpenid',
211+
complete: res => {
212+
app.globalData.openid = res.result.openid
213+
app.globalData.appid = res.result.appid
214+
this.setData({
215+
openid: res.result.openid
216+
})
217+
}
218+
})
219+
}
220+
//获取夜间模式
221+
if (app.globalData.theme) {
222+
this.setData({
223+
theme: app.globalData.theme
224+
})
225+
} else {
226+
wx.getSystemInfo({
227+
success: (res) => {
228+
this.setData({
229+
theme: res.theme
230+
})
231+
}
232+
})
233+
}
234+
//获取群组
235+
wx.cloud.database().collection('group').get()
236+
.then(res => {
237+
// console.log(res)
238+
this.setData({
239+
array: res.data
240+
})
241+
})
242+
.catch(err => {
243+
console.log(err)
244+
})
245+
//获取昵称
246+
wx.cloud.database().collection('user').where({
247+
_openid : this.data.openid
248+
}).get()
249+
.then(res => {
250+
console.log(res[0].nickname)
251+
this.setData({
252+
nickname: res[0].nickname
253+
})
254+
})
255+
.catch(err => {})
82256
},
83257

84258
/**

0 commit comments

Comments
 (0)