Skip to content

Commit

Permalink
1.3.0
Browse files Browse the repository at this point in the history
-完全重构数据交互和存储方式
  • Loading branch information
QlQlqiqi committed Sep 10, 2021
1 parent eadce1d commit ef9f430
Show file tree
Hide file tree
Showing 15 changed files with 842 additions and 873 deletions.
117 changes: 1 addition & 116 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,123 +1,8 @@
const util = require('./src/utils/util');
App({
globalData: {
checkUrl: 'https://witime.wizzstudio.com/check/',
url: 'https://witime.wizzstudio.com/',
// success 用于判断数据是否请求完成
success: 0
url: 'http://297mo66766.imdo.co/'
},
onLaunch() {
let _this = this;
// 数据同步了就不必再从后端获取
// 数据同步包括:任务 tasks、清单 lists 和 个性签名 signText
let exist = wx.getStorageSync('exist');
// 获取数据并保存在本地
if(!exist) {
util.login(_this.globalData.url + 'login/login/')
.then(res => {
let token = res.data.token;
let owner = res.data.user_id;
let lists = [];
let tasks = [];
let signText = '';
// 先请求 lists
util.myRequest({
url: _this.globalData.checkUrl + 'taglist/?owner=' + JSON.stringify(owner),
header: { token: token },
method: "GET"
}).then(function(res) {
res.data.forEach(function(item) {
let list = {
title: item.tag,
icon: item.icon,
url: item.url
}
lists.push(list);
});
if(!lists.length)
lists = [
{ title: "个人清单", icon: "/src/image/menu-self-list0.svg" },
{ title: "工作清单", icon: "/src/image/menu-self-list1.svg" }
]
wx.setStorageSync('lists', JSON.stringify(lists));
_this.globalData.success++;
})
// 再请求 tasks
.then(function() {
util.myRequest({
url: _this.globalData.checkUrl + 'check/?owner=' + JSON.stringify(owner),
header: { token: token },
method: "GET"
}).then(function(res) {
// 将请求到的 res.data 中数据转化为本地数据 tasks ,并保存在本地
res.data.forEach(item => {
// 根据 c_time 和 e_date 得到 remind
let div = (new Date(item.e_time).getTime() - new Date(item.c_time).getTime()) / 1000;
let remind = [0, 60, 300, 600, 1800, 3600].indexOf(div);
// 根据 lists 得到该 item 的 list
let list = {};
for(let tmpList of lists) {
if(tmpList.url === item.tag) {
list.title = tmpList.title;
list.icon = tmpList.icon;
break;
}
}
let task = {
id: util.getUniqueId(),
priority: item.priority,
repeat: item.repeat,
date: item.e_time,
remind: remind,
finish: item.finish === 0? false: true,
finishDate: item.fin_date || item.e_time,
content: item.text,
desc: item.todo_desc === "default"? "": item.todo_desc,
list: list,
delete: item.todo_delete === 0? false: true,
rating: item.star,
feeling: item.star_text === "default"? "": item.star_text,
url: item.url
};
tasks.push(task);
});
wx.setStorageSync('tasks', JSON.stringify(tasks));
// console.log(tasks)
_this.globalData.success++;
});
})
// 请求 signText
util.myRequest({
url: _this.globalData.checkUrl + 'sign/?owner=' + JSON.stringify(owner),
header: { token: token },
method: "GET",
}).then(function(res) {
if(!res.data.length) {
signText = "好好学习 天天向上";
util.myRequest({
url: _this.globalData.checkUrl + 'sign/?owner=' + JSON.stringify(owner),
header: { Authorization: "Token " + token },
method: "POST",
data: {
signText: signText,
owner: _this.globalData.url + 'login/user/' + owner + '/'
}
}).then(res => wx.setStorage({key: 'signTextUrl', data: JSON.stringify(res.data.url)}))
}
else signText = res.data[0].signText;
wx.setStorageSync('signText', JSON.stringify(signText));
_this.globalData.success++;
// console.log(signText)
})
wx.setStorageSync('token', JSON.stringify(token));
wx.setStorageSync('owner', JSON.stringify(owner));
wx.setStorageSync('uniqueId', JSON.stringify(10000));
});
}
else {
this.globalData.success = 3;
}

// 获取设备相关信息
let menuButtonObject = wx.getMenuButtonBoundingClientRect();
wx.getSystemInfo({
Expand Down
2 changes: 1 addition & 1 deletion project.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"minifyWXML": true
},
"compileType": "miniprogram",
"libVersion": "2.18.1",
"libVersion": "2.19.3",
"appid": "wx5bbb7bc983c50b3d",
"projectname": "Self%20Discipline%20Tree%20Hole",
"debugOptions": {
Expand Down
2 changes: 1 addition & 1 deletion src/components/menu/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ Component({
this.setData({
showDialog: true,
dialogTitle: '提示',
dialogContent: '是否删除该清单?(清单内任务自动进入[个人清单]内)',
dialogContent: '是否删除该清单?(清单内任务自动进入个人清单内)',
buttons: [{text: '取消'}, {text: '确认'}]
})
let _this = this;
Expand Down
1 change: 0 additions & 1 deletion src/components/task-item/task-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ Component({
// 显示日期
_showDate: function() {
let showDate = util.dateInToOut(this.properties.date);
console.log(showDate)
this.setData({
showDate: showDate
})
Expand Down
48 changes: 36 additions & 12 deletions src/pages/add-self-list/add-self-list.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const app = getApp();
const util = require("../../utils/util");
const store = require('../../store/store');
Component({
/**
* 组件的属性列表
Expand Down Expand Up @@ -29,23 +31,46 @@ Component({
* 组件的方法列表
*/
methods: {
// 检查输入名是否合法,然后保存数据到本地
ensure: function() {
// 检查输入名是否合法,然后保存数据
ensure: async function() {
if(!this.data.listTitle.length) {
this.setData({
show: true
});
return;
}
// 触发事件并回退上一个页面
const eventChannel = this.getOpenerEventChannel();
eventChannel.emit("_handleSaveData", {
lists: [{
title: this.data.listTitle,
icon: this.properties.listIcon[this.data.selectedIcon]
}]
wx.showLoading({
title: '正在保存数据...',
mask: true
})
let {owner, token} = await util.getTokenAndOwner(app.globalData.url + 'login/login/');
let list = {
title: this.data.listTitle,
icon: this.properties.listIcon[this.data.selectedIcon]
}
await util.myRequest({
url: app.globalData.url + 'check/taglist/?owner=' + JSON.stringify(owner),
header: { Authorization: "Token " + token },
method: "POST",
data: util.formatListsFromLocalToSql([list], {owner})[0]
});
wx.navigateBack()
(await store.getDataFromSqlByUrl(app.globalData.url + 'check/taglist/', {owner, token}))
.forEach(listSql => {
if(listSql.tag === list.title)
list.urlSql = listSql.url;
})
let lists = JSON.parse(wx.getStorageSync('lists'));
lists.push(list);
wx.setStorageSync('lists', JSON.stringify(lists));
wx.hideLoading({
success: () => {
wx.showToast({
title: '已完成',
duration: 800
})
},
})
this.handleBack()
},
dialogClose: function() {
this.setData({
Expand Down Expand Up @@ -73,7 +98,6 @@ Component({
windowHeight: app.globalData.windowHeight,
windowWidth: app.globalData.windowWidth
});
},
onUnload: function() {}
}
}
})
Loading

0 comments on commit ef9f430

Please sign in to comment.