Skip to content

Commit

Permalink
style: code style to es6
Browse files Browse the repository at this point in the history
  • Loading branch information
airingursb committed Sep 4, 2019
1 parent 57fed47 commit 7e46e37
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 243 deletions.
39 changes: 18 additions & 21 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,40 @@
//app.js
// app.js

var hotapp=require('./utils/hotapp.js');
//hotapp.setDebug(true);
const hotapp = require('./utils/hotapp.js')
// hotapp.setDebug(true)

var wilddog=require('./utils/wilddog-weapp-all.js');
var config = {
const wilddog = require('./utils/wilddog-weapp-all.js')
const config = {
syncURL: 'https://miemie.wilddogio.com',
authDomain: 'miemie.wilddog.com'
}

App({
onLaunch: function () {
//调用API从本地缓存中获取数据
var logs = wx.getStorageSync('logs') || []
onLaunch: () => {
// 调用 API 从本地缓存中获取数据
const logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)

wilddog.initializeApp(config)

},
getUserInfo:function(cb){
var that = this
if(this.globalData.userInfo){
getUserInfo: cb => {
if (this.globalData.userInfo) {
typeof cb == "function" && cb(this.globalData.userInfo)
}else{
//调用登录接口
} else {
wx.login({
success: function () {
success: () => {
wx.getUserInfo({
success: function (res) {
that.globalData.userInfo = res.userInfo
typeof cb == "function" && cb(that.globalData.userInfo)
success: res => {
this.globalData.userInfo = res.userInfo
typeof cb == "function" && cb(this.globalData.userInfo)
}
})
}
})
}
},
globalData:{
userInfo:null
globalData: {
userInfo: null
}
})
})
18 changes: 8 additions & 10 deletions pages/index/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,18 @@ Page({
motto: 'Hello World',
userInfo: {}
},
//事件处理函数
bindViewTap: function() {
// 事件处理函数
bindViewTap: () => {
wx.navigateTo({
url: '../logs/logs'
})
},
onLoad: function () {
console.log('onLoad')
var that = this
//调用应用实例的方法获取全局数据
app.getUserInfo(function(userInfo){
//更新数据
that.setData({
userInfo:userInfo
onLoad: () => {
// 调用应用实例的方法获取全局数据
app.getUserInfo(userInfo => {
// 更新数据
this.setData({
userInfo: userInfo
})
})
}
Expand Down
51 changes: 17 additions & 34 deletions pages/search/detail/detail.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,22 @@
// pages/settings/detail/detail.js
Page({
data:{},
onLoad:function(option){
var word = option.content
data: {},
onLoad: option => {
const word = option.content

var that = this;
wx.request({
url: 'https://api.shanbay.com/bdc/search/?word=' + word,
data: {},
method: 'GET',
success: function (res) {
console.log(res)
that.setData({
content: res.data.data.content,
audio: res.data.data.audio_addresses.us[0],
pron: res.data.data.pron,
definition: res.data.data.definition
})
},
fail: function () {
},
complete: function () {
}
wx.request({
url: `https://api.shanbay.com/bdc/search/?word=${word}`,
data: {},
method: 'GET',
success: res => {
const data = res.data.data
this.setData({
content: data.content,
audio: data.audio_addresses.us[0],
pron: data.pron,
definition: data.definition
})
},
onReady:function(){
// 页面渲染完成
},
onShow:function(){
// 页面显示
},
onHide:function(){
// 页面隐藏
},
onUnload:function(){
// 页面关闭
}
})
}
})
})
62 changes: 10 additions & 52 deletions pages/search/search.js
Original file line number Diff line number Diff line change
@@ -1,77 +1,35 @@
Page({
data: {

},
onLoad: function (options) {
// 生命周期函数--监听页面加载

},
onShareAppMessage: function () {
// 用户点击右上角分享
return {
title: '', // 分享标题
desc: '', // 分享描述
path: '' // 分享路径
}
},

search: function (e) {
var that = this
var content = e.detail.value
search: e => {
let content = e.detail.value
wx.request({

url: 'https://api.shanbay.com/bdc/search/?word=' + content,
url: `https://api.shanbay.com/bdc/search/?word=${content}`,
data: {},
method: 'GET',
success: function (res) {
console.log(res)

var msg = res.data.msg
success: res => {
const { msg } = res.data
if (msg == "SUCCESS") {
wx.navigateTo({
url: './detail/detail?content=' + content,
success: function (res) {
// success
},
fail: function () {
// fail
},
complete: function () {
// complete
}
url: `./detail/detail?content=${content}`
})
} else {
wx.showModal({
title: '提示',
content: '对不起,查询不到该词信息',
showCancel: false,
success: function (res) {
if (res.confirm) {
console.log('用户点击确定')
}
}
showCancel: false
})
}

},
fail: function () {
},
complete: function () {
}
})

},

help: function () {
help: () => {
wx.showModal({
title: '提示',
content: '输入单词后点击回车键即可查询',
showCancel: false,
success: function (res) {
if (res.confirm) {
console.log('用户点击确定')
}
}
showCancel: false
})
}
})
})
18 changes: 3 additions & 15 deletions pages/settings/clause/clause.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
// pages/settings/clause/clause.js
Page({
data:{},
onLoad:function(options){
data: {},
onLoad: options => {
// 页面初始化 options为页面跳转所带来的参数
},
onReady:function(){
// 页面渲染完成
},
onShow:function(){
// 页面显示
},
onHide:function(){
// 页面隐藏
},
onUnload:function(){
// 页面关闭
}
})
})
59 changes: 26 additions & 33 deletions pages/settings/feedback/feedback.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// pages/settings/feedback/feedback.js

var wilddog = require('../../../utils/wilddog-weapp-all')
var config = {
const wilddog = require('../../../utils/wilddog-weapp-all')
const config = {
syncURL: 'https://miemie.wilddogio.com',
authDomain: 'miemie.wilddog.com'
}
var app = getApp()
const app = getApp()


Page({
Expand All @@ -14,65 +14,58 @@ Page({
content: "",
connect: ""
},
onLoad: function (options) {
onLoad: options => {

const that = this;
// 页面初始化 options为页面跳转所带来的参数
app.getUserInfo(function (userInfo) {
that.setData({
app.getUserInfo(userInfo => {
this.setData({
userInfo: userInfo
})
})
},
getContent: function (e) {
getContent: e => {
this.setData({
content: e.detail.value
})
},
getConnection: function (e) {
getConnection: e => {
this.setData({
connect: e.detail.value
})
},
getNowFormatDate: function () {
var date = new Date();
var seperator1 = "-";
var seperator2 = ":";
var month = date.getMonth() + 1;
var strDate = date.getDate();
getNowFormatDate: () => {
const date = new Date()
const seperator1 = "-"
const seperator2 = ":"
const month = date.getMonth() + 1
const strDate = date.getDate()
if (month >= 1 && month <= 9) {
month = "0" + month;
month = "0" + month
}
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
strDate = "0" + strDate
}
var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
return date.getFullYear() + seperator1 + month + seperator1 + strDate
+ " " + date.getHours() + seperator2 + date.getMinutes()
+ seperator2 + date.getSeconds();
return currentdate;
+ seperator2 + date.getSeconds()
},
submitSuggestion: function () {
submitSuggestion: () => {
wilddog.initializeApp(config)
var ref = wilddog.sync().ref("/web/saving-data/feedback");
// child() 用来定位到某个节点。
const ref = wilddog.sync().ref("/web/saving-data/feedback")

var currentdate = this.getNowFormatDate()
const currentdate = this.getNowFormatDate()

// child() 用来定位到某个节点。
ref.child(currentdate).set({
"content": this.data.content,
"connect": this.data.connect,
"user": this.data.userInfo.nickName
});
})

wx.showModal({
title: '提示',
content: '提交成功!感谢您的反馈!',
showCancel: false,
success: function (res) {
if (res.confirm) {
console.log('用户点击确定')
}
}
showCancel: false
})
}

})
})
18 changes: 3 additions & 15 deletions pages/settings/help/help.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
// pages/settings/help/help.js
Page({
data:{},
onLoad:function(options){
data: {},
onLoad: options => {
// 页面初始化 options为页面跳转所带来的参数
},
onReady:function(){
// 页面渲染完成
},
onShow:function(){
// 页面显示
},
onHide:function(){
// 页面隐藏
},
onUnload:function(){
// 页面关闭
}
})
})
Loading

0 comments on commit 7e46e37

Please sign in to comment.