diff --git a/lib/base.js b/lib/base.js
index 58b09654..c0399555 100644
--- a/lib/base.js
+++ b/lib/base.js
@@ -150,6 +150,7 @@ Volcanos("base", {help: "数据类型",
return res
}
try { res = JSON.parse(str)
+ res.text = res.text||str
res.type = res.type||"json"
} catch (e) {
res = {type: "text", text: str}
diff --git a/publish/client/mp/app.js b/publish/client/mp/app.js
index c52e4b1a..0950874f 100644
--- a/publish/client/mp/app.js
+++ b/publish/client/mp/app.js
@@ -1,40 +1,29 @@
const kit = require("utils/kit.js")
App({
- // data: {}, conf: {serve: "https://shylinux.com/chat", space: "mac"},
data: {}, conf: {serve: "https://shylinux.com/chat", space: ""},
request: function(cmd, data, cb) { var app = this; data.sessid = app.conf.sessid, data.pod = app.conf.space
wx.request({method: "POST", url: app.conf.serve+"/"+cmd, data: data, success: function(res) { var msg = res.data
- if (res.statusCode == 401) { return app.usercode(function() {app.request(cmd, data, cb)}) }
+ if (res.statusCode == 401) { return app.usercode(function() { app.request(cmd, data, cb) }) }
console.log("POST", cmd, msg)
msg.__proto__ = {
- nRow: function() { return msg.append && msg.append[0] && msg[msg.append[0]].length || 0 },
Result: function() { return msg.result && msg.result.length > 0 && msg.result.join("") || "" },
- Table: function(cb) { var row = 0
+ Length: function() { var max = 0; if (!msg.append) { return max }
for (var i = 0; i < msg.append.length; i++) {
- row = msg[msg.append[i]].length > row? msg[msg.append[i]].length: row
- }
- for (var i = 0; i < row; i++) { var line = {}
- for (var k in msg.append) {
- line[msg.append[k]] = msg[msg.append[k]][i]
- }
- typeof cb == "function" && cb(line, i, row)
- }
+ var len = msg[msg.append[i]].length; len > max && (max = len)
+ }; return max
+ },
+ Table: function(cb) { var res = []
+ for (var i = 0; i < msg.Length(); i++) { var line = {}
+ for (var k in msg.append) { line[msg.append[k]] = msg[msg.append[k]][i] }
+ typeof cb == "function" && cb(line, i, msg.Length())
+ res.push(line)
+ }; return res
},
}
- var row = 0
- var index = []
- if (msg.append) {
- for (var i = 0; i < msg.append.length; i++) {
- row = msg[msg.append[i]].length > row? msg[msg.append[i]].length: row
- }
- for (var i = 0; i < row; i++) {
- index.push(i)
- }
- }
- msg._index = index
+ var index = []; for (var i = 0; i < msg.Length(); i++) { index.push(i) }; msg._index = index
typeof cb == "function" && cb(msg)
}})
},
@@ -43,24 +32,20 @@ App({
},
usercode: function(cb) { var app = this
wx.login({success: function(res) { app.request("mp/login/sess", {code: res.code}, function(msg) {
- wx.setStorage({key: "sessid", data: msg.Result()})
- app.conf.sessid = msg.Result(), typeof cb == "function" && cb()
+ wx.setStorage({key: "sessid", data: app.conf.sessid = msg.Result()})
+ typeof cb == "function" && cb()
})}})
},
userinfo: function(cb) { var app = this
- if (app.conf.userInfo) {
- app.request("mp/login/user", app.conf.userInfo, function(msg) {
- typeof cb == "function" && cb(app.conf.userInfo)
- })
- return
- }
- app.usercode(function() {
- wx.getSetting({ success: function(res) { res.authSetting['scope.userInfo'] && wx.getUserInfo({success: function(res) {
- app.request("mp/login/user", res.userInfo, function(msg) { app.conf.userInfo = res.userInfo
- typeof cb == "function" && cb(res.userInfo)
+ app.conf.userInfo? app.request("mp/login/user", app.conf.userInfo, function(msg) {
+ typeof cb == "function" && cb(app.conf.userInfo)
+ }): app.usercode(function() { wx.getSetting({success: function(res) {
+ res.authSetting['scope.userInfo'] && wx.getUserInfo({success: function(res) {
+ app.request("mp/login/user", app.conf.userInfo = res.userInfo, function(msg) {
+ typeof cb == "function" && cb(app.conf.userInfo)
})
- }})}})
- })
+ }})
+ }}) })
},
location: function(arg) { wx.chooseLocation(arg) },
@@ -71,58 +56,20 @@ App({
console.log("jump", next), wx.navigateTo({url: next, success: cb})
},
scans: function(cb) { var app = this
- wx.scanCode({success: function(res) { console.log("scan", res)
- try {
- var value = JSON.parse(res.result)
- } catch(e) {
- try {
- var value = {"type": "url", "text": res.result}
- var ls = res.result.split("?"); if (ls.length > 1) { ls = ls[1].split("&")
- for (var i = 0; i < ls.length; i++) { var vs = ls[i].split("=")
- value[vs[0]] = decodeURIComponent(vs[1])
- }
- }
- } catch(e) {
- typeof cb == "function" && cb({type: "", text: res.result})
- return
- }
- }
+ wx.scanCode({success: function(res) { var data = kit.parseJSON(res)
+ if (typeof cb == "function" && cb(data)) { return }
- switch (value.type) {
- case "share":
- switch (value.name) {
- case "invite":
- app.userinfo(function(userInfo) {
- app.modal("接受邀请", value.name, function(res) {
- res.confirm && app.request("mp/login/auth", value, function(msg) {
- app.toast("回执成功")
- })
- })
- })
- break
- }
- break
-
- case "login":
+ switch (data.type) {
+ case "auth":
app.userinfo(function(userInfo) {
- app.modal("授权登录", value.name, function(res) {
- res.confirm && app.request("mp/login/auth", value, function(msg) {
+ app.modal("授权登录", data.name, function(res) {
+ res.confirm && app.request("mp/login/scan", data, function(msg) {
app.toast("授权成功")
})
})
})
break
- case "active":
- app.userinfo(function(userInfo) {
- app.modal("授权登录", value.name, function(res) {
- res.confirm && app.request("mp/login/auth", value, function(msg) {
- app.toast("授权成功")
- })
- })
- })
- break
- default:
- typeof cb == "function" && cb(value)
+ default: app.request("mp/login/scan", res)
}
}})
},
diff --git a/publish/client/mp/app.wxml b/publish/client/mp/app.wxml
index 16dd762e..1ed623f0 100644
--- a/publish/client/mp/app.wxml
+++ b/publish/client/mp/app.wxml
@@ -1,13 +1,8 @@
-
+
-
-
- {{item}}
-
-
diff --git a/publish/client/mp/pages/action/action.js b/publish/client/mp/pages/action/action.js
index 4cc325d2..8bf16d1c 100644
--- a/publish/client/mp/pages/action/action.js
+++ b/publish/client/mp/pages/action/action.js
@@ -3,49 +3,50 @@ const app = getApp()
Page({
data: {
- action: ["扫码", "刷新", "清屏", "串行", "并行"],
river: "", storm: "", title: "",
+ action: ["刷新", "扫码", "清屏", "串行", "并行"],
res: [], his: {}, inputs: {},
},
action: {
- "扫码": function(event, page, data, name) {
- // app.jumps("scans/scans")
- app.scans(function(res) {
- res["sess.river"] = page.data.river
- res["sess.storm"] = page.data.storm
- app.request("mp/login/scan", res)
- page.onaction(event, res, res.name)
- })
- },
- "刷新": function(event, page, data, name) {
- var list = []; app.data[page.data.river+page.data.storm] = page.data.res = list
+ "刷新": function(event, page) { var list = []
+ app.data[page.data.river+page.data.storm] = page.data.res = list
+
wx.showLoading()
- app.request("action", {cmds: [page.data.river, page.data.storm]}, function(msg) {
- wx.hideLoading()
- msg.Table(function(line, index) {
- line.name = line.name.split(" ")[0]
- page.data.his[index] = []
- line.inputs = JSON.parse(line.list)
+ app.request("action", {cmds: [page.data.river, page.data.storm]}, function(msg) { wx.hideLoading()
+ msg.Table(function(line, index) { list.push(line)
line.feature = JSON.parse(line.meta)
+ line.inputs = JSON.parse(line.list)
+ line.name = line.name.split(" ")[0]
+
if (!line.inputs || line.inputs.length === 0) {
line.inputs = [{_input: "text"}, {_input: "button", value: "执行"}]
}
- list.push(line), line.inputs.forEach(function(input) {
- input.action = input.action || input.value
+
+ line.inputs.forEach(function(input) { input.action = input.action || input.value
+ input.value = kit.Value(line, "feature.trans."+input.name) || input.value
input.value == "auto" && (input.value = "")
- input.value = input.value || kit.Value(line, "feature.trans."+input.name)
+
if (input.value && input.value.indexOf("@") == 0) {
- input.value = ""
+ input.action = input.value.slice(1), input.value = ""
}
if (input._input == "select") {
- input.values = input.values || input.value && input.value.split("|")
+ input.values = input.values || input.value && kit.Split(input.value)
}
input._input == "button" && input.action == "auto" && page.run(event, index)
})
- })
- page.setData({res: list})
+ }), page.data.his = [], page.setData({res: list})
})
},
+ "扫码": function(event, page) { app.scans(function(res) {
+ switch (res.type) {
+ case "button": res.name && page.onaction(event, res); break
+ default: return false
+ } return true
+ }) },
+ "清屏": function(event, page) {
+ kit.List(page.data.res, function(field, index) { delete(field.msg) })
+ page.setData({res: page.data.res})
+ },
"串行": function(event, page, data, name) {
function cb(i) {
page.run(event, i, null, function() {i < page.data.res.length - 1&& cb(i+1)})
@@ -57,17 +58,10 @@ Page({
page.run(event, index)
})
},
- "清屏": function(event, page, data, name) {
- kit.List(page.data.res, function(field, index) {
- delete(field.msg)
- })
- page.setData({res: page.data.res})
- },
},
- onaction: function(event, data, name) {
- data = data || event.target.dataset, name = name || data.name
- console.log("action", "action", name)
- this.action[name](event, this, data)
+ onaction: function(event, data) { data = data || event.target.dataset
+ console.log("action", "river", data.name)
+ this.action[data.name](event, this)
},
run: function(event, order, cmd, cb) {var page = this, field = page.data.res[order]
@@ -157,7 +151,6 @@ Page({
onLoad: function (options) {
console.log("page", "action", options)
- app.conf.sessid = options.sessid || app.conf.sessid
this.data.river = options.river
this.data.storm = options.storm
this.data.title = options.title
@@ -165,20 +158,16 @@ Page({
var data = app.data[options.river+options.storm]
if (data) { return this.setData({res: this.data.res = data}) }
- this.onaction({}, {}, "刷新")
+ this.onaction({}, {name: "刷新"})
},
onReady: function () {},
onShow: function () {},
onHide: function () {},
onUnload: function () {},
- onPullDownRefresh: function () {
- this.onaction({}, {}, "刷新")
- },
onReachBottom: function () {},
+ onPullDownRefresh: function () { this.onaction({}, {name: "刷新"}) },
onShareAppMessage: function (res) {
- console.log("action", "share", res)
- return {
- title: this.data.title,
+ return { title: this.data.title,
path: "pages/action/action?river="+this.data.river+"&storm="+this.data.storm+"&title="+this.data.title,
}
},
diff --git a/publish/client/mp/pages/river/river.js b/publish/client/mp/pages/river/river.js
index 14983590..15d54137 100644
--- a/publish/client/mp/pages/river/river.js
+++ b/publish/client/mp/pages/river/river.js
@@ -3,82 +3,51 @@ const app = getApp()
Page({
data: {
- action: ["扫码", "刷新", "登录"],
river: {},
+ action: ["刷新", "扫码", "登录"],
},
action: {
- "扫码": function(event, page, data) { app.scans(function(res) {
+ "刷新": function(event, page) { wx.showLoading()
+ app.request("river", {}, function(msg) { wx.hideLoading()
+ page.setData({river: msg.Table()})
+ })
+ },
+ "扫码": function(event, page) { app.scans(function(res) {
switch (res.type) {
- case "url":
- app.request("mp/login/scan", res, function(msg) {
- page.onaction({}, {}, "刷新")
- })
- break
- default:
- res.name && page.onaction(event, res, res.name)
- }
+ case "button": res.name && page.onaction(event, res); break
+ default: return false
+ } return true
}) },
- "刷新": function(event, page, data) {
- wx.showLoading()
- app.request("river", {}, function(msg) {
- wx.hideLoading()
- var river = {}; msg.Table(function(value) {
- river[value.hash] = value
- })
- page.setData({river: river})
- })
- },
- "登录": function(event, page, data) { app.conf.sessid = "",
- app.userinfo(function(res) {
- page.onaction(event, data, "刷新")
- })
+ "登录": function(event, page) { app.conf.sessid = ""
+ app.userinfo(function(res) { page.onaction(event, {name: "刷新"}) })
},
},
- onaction: function(event, data, name) {
- data = data || event.target.dataset, name = name || data.name
- console.log("action", "river", name)
- this.action[name](event, this, data)
+ onaction: function(event, data) { data = data || event.target.dataset
+ console.log("action", "river", data.name)
+ this.action[data.name](event, this)
},
- ondetail: function(event, data) { var page = this
- data = data || event.target.dataset.item
- console.log("detail", "river", data)
-
- var river = page.data.river[data.hash]
- if (river.tool) {
- river.hidetool = !river.hidetool
- page.setData({river: page.data.river})
- return
+ ondetail: function(event, data) { data = data || event.target.dataset
+ var page = this, river = page.data.river[data.index]
+ river._show = !river._show; if (river.list) {
+ return page.setData({river: page.data.river})
}
wx.showLoading()
- app.request("river", {cmds: [data.hash, "tool"]}, function(msg) {
- wx.hideLoading()
- river.tool = {}; msg.Table(function(value) {
- river.tool[value.hash] = value
- value.river = data
- })
- page.setData({river: page.data.river})
+ app.request("river", {cmds: [river.hash, "tool"]}, function(msg) { wx.hideLoading()
+ river.list = msg.Table(), page.setData({river: page.data.river})
})
},
- onchange: function(event, data) { var page = this
- data = data || event.target.dataset.item
- app.jumps("action/action", {river: data.river.hash, storm: data.hash, title: data.river.name+"."+data.name})
+ onchange: function(event, data) { data = data || event.target.dataset
+ var river = this.data.river[data.index]; var storm = river.list[data.i]
+ app.jumps("action/action", {river: river.hash, storm: storm.hash, title: river.name+"."+storm.name})
},
- onLoad: function (options) { var page = this
- console.log("page", "river", options)
- app.conf.sessid = options.sessid || app.conf.sessid
- app.usercode(function() {
- page.onaction({}, options, "刷新")
- })
- },
+ onLoad: function (options) { this.onaction({}, {name: "刷新"}) },
onReady: function () {},
onShow: function () {},
onHide: function () {},
onUnload: function () {},
- onPullDownRefresh: function () {
- this.onaction({}, {}, "刷新")
- },
onReachBottom: function () {},
+ onPullDownRefresh: function () { this.onaction({}, {name: "刷新"}) },
onShareAppMessage: function () {}
})
diff --git a/publish/client/mp/pages/river/river.wxml b/publish/client/mp/pages/river/river.wxml
index e9e54504..97372222 100644
--- a/publish/client/mp/pages/river/river.wxml
+++ b/publish/client/mp/pages/river/river.wxml
@@ -1,12 +1,12 @@
-
-
- {{item.name}}
-
- {{item.name}}
+
+ {{item.name}}
+
+ {{item.name}}
diff --git a/publish/client/mp/project.config.json b/publish/client/mp/project.config.json
index 7b64dc28..f725c39a 100644
--- a/publish/client/mp/project.config.json
+++ b/publish/client/mp/project.config.json
@@ -1,89 +1,108 @@
{
- "description": "项目配置文件",
- "packOptions": {
- "ignore": []
- },
- "setting": {
- "urlCheck": true,
- "es6": true,
- "postcss": true,
- "minified": true,
- "newFeature": true,
- "autoAudits": false,
- "coverView": true,
- "showShadowRootInWxmlPanel": true,
- "scopeDataCheck": false
- },
- "compileType": "miniprogram",
- "libVersion": "2.0.4",
- "appid": "wxf4e5104d83476ed6",
- "projectname": "%E7%BB%88%E7%AB%AF%E5%B7%A5%E5%85%B7%E9%93%BE",
- "debugOptions": {
- "hidedInDevtools": []
- },
- "isGameTourist": false,
- "simulatorType": "wechat",
- "simulatorPluginLibVersion": {},
- "condition": {
- "search": {
- "current": -1,
- "list": []
- },
- "conversation": {
- "current": -1,
- "list": []
- },
- "plugin": {
- "current": -1,
- "list": []
- },
- "game": {
- "currentL": -1,
- "list": []
- },
- "gamePlugin": {
- "current": -1,
- "list": []
- },
- "miniprogram": {
- "current": -1,
- "list": [
- {
- "id": 0,
- "name": "pages/action/action",
- "pathName": "pages/action/action",
- "query": "river=c796cd&storm=9092d5",
- "scene": 1008
- },
- {
- "id": 1,
- "name": "action",
- "pathName": "pages/action/action",
- "query": "river=d022b3&storm= c22d21",
- "scene": null
- },
- {
- "id": 2,
- "name": "pages/river/river",
- "pathName": "pages/river/river",
- "query": "river=c796cd&storm=9092d5",
- "scene": null
- },
- {
- "id": -1,
- "name": "pages/scans/scans",
- "pathName": "pages/scans/scans",
- "query": "river=c796cd&storm=9092d5",
- "scene": null
- },
- {
- "id": 4,
- "name": "pages/action/action",
- "pathName": "pages/action/action",
- "query": "river=d82c1d&storm=12d1d7&title=mac.paste",
- "scene": null
- }
- ]
- }
- }
+ "description": "项目配置文件",
+ "packOptions": {
+ "ignore": []
+ },
+ "setting": {
+ "urlCheck": true,
+ "es6": true,
+ "enhance": false,
+ "postcss": true,
+ "preloadBackgroundData": false,
+ "minified": true,
+ "newFeature": true,
+ "coverView": true,
+ "nodeModules": false,
+ "autoAudits": false,
+ "showShadowRootInWxmlPanel": true,
+ "scopeDataCheck": false,
+ "uglifyFileName": false,
+ "checkInvalidKey": true,
+ "checkSiteMap": true,
+ "uploadWithSourceMap": true,
+ "compileHotReLoad": false,
+ "useMultiFrameRuntime": false,
+ "useApiHook": true,
+ "babelSetting": {
+ "ignore": [],
+ "disablePlugins": [],
+ "outputPath": ""
+ },
+ "enableEngineNative": false,
+ "bundle": false,
+ "useIsolateContext": true,
+ "useCompilerModule": true,
+ "userConfirmedUseCompilerModuleSwitch": false,
+ "userConfirmedBundleSwitch": false,
+ "packNpmManually": false,
+ "packNpmRelationList": [],
+ "minifyWXSS": true
+ },
+ "compileType": "miniprogram",
+ "libVersion": "2.0.4",
+ "appid": "wxf4e5104d83476ed6",
+ "projectname": "%E7%BB%88%E7%AB%AF%E5%B7%A5%E5%85%B7%E9%93%BE",
+ "debugOptions": {
+ "hidedInDevtools": []
+ },
+ "isGameTourist": false,
+ "simulatorType": "wechat",
+ "simulatorPluginLibVersion": {},
+ "condition": {
+ "search": {
+ "list": []
+ },
+ "conversation": {
+ "list": []
+ },
+ "plugin": {
+ "list": []
+ },
+ "game": {
+ "currentL": -1,
+ "list": []
+ },
+ "gamePlugin": {
+ "list": []
+ },
+ "miniprogram": {
+ "list": [
+ {
+ "id": 0,
+ "name": "pages/action/action",
+ "pathName": "pages/action/action",
+ "query": "river=c796cd&storm=9092d5",
+ "scene": 1008
+ },
+ {
+ "id": 1,
+ "name": "action",
+ "pathName": "pages/action/action",
+ "query": "river=d022b3&storm= c22d21",
+ "scene": null
+ },
+ {
+ "id": 2,
+ "name": "pages/river/river",
+ "pathName": "pages/river/river",
+ "query": "river=c796cd&storm=9092d5",
+ "scene": null
+ },
+ {
+ "id": -1,
+ "name": "pages/scans/scans",
+ "pathName": "pages/scans/scans",
+ "query": "river=c796cd&storm=9092d5",
+ "scene": null
+ },
+ {
+ "id": 4,
+ "name": "pages/action/action",
+ "pathName": "pages/action/action",
+ "query": "river=d82c1d&storm=12d1d7&title=mac.paste",
+ "scene": null
+ }
+ ]
+ }
+ }
}
\ No newline at end of file
diff --git a/publish/client/mp/utils/kit.js b/publish/client/mp/utils/kit.js
index 8c5fae8d..2ae005ab 100644
--- a/publish/client/mp/utils/kit.js
+++ b/publish/client/mp/utils/kit.js
@@ -31,12 +31,102 @@ module.exports = {
cb(k, list[k])
}
},
- Value: function(item, key) {
- var p = item, ls = key.split(".")
- while (p && ls.length > 0) {
+ Value: function(data, key, value) {
+ if (data == undefined) { return }
+ if (key == undefined) { return data }
+ if (typeof key == "object") { for (var k in key) {
+ arguments.callee.call(this, data, k, key[k])
+ }; return data }
+
+ if (value != undefined) { data[key] = value }
+ if (data[key] != undefined) { return data[key] }
+
+ var p = data, ls = key.split("."); while (p && ls.length > 0) {
+ if (ls[0] == "-1") { ls[0] = p.length-1 }
p = p[ls[0]], ls = ls.slice(1)
+ }; return p
+ },
+
+ Split: function(str) { if (!str || !str.length) { return [] }
+ var opt = {detail: false}, arg = []; for (var i = 1; i < arguments.length; i++) {
+ typeof arguments[i] == "object"? opt = arguments[i]: arg.push(arguments[i])
}
- return p
+
+ function _list(str) { var res = {}; for (var i = 0; i < str.length; i++) { res[str[i]] = true }; return res }
+ // 空白符
+ var seps = _list(arg[0]||"\t ,\n")
+ // 分隔符
+ var sups = _list(arg[1]||"{[(.:)]}")
+ // 引用符
+ var subs = _list(arg[2]||"'\"`")
+
+ // 开始分词
+ var res = [], list = str
+ var left = "", space = true, begin = 0
+ for (var i = 0; i < list.length; i++) {
+ if (seps[list[i]]) {
+ // 空白符
+ if (left == "") {
+ if (!space) {
+ res.push(list.slice(begin, i))
+ }
+ opt.detail && res.push({text: list.slice(i, i+1), type: "space", left: left})
+ space = true, begin = i+1
+ }
+ } else if (subs[list[i]]) {
+ // 引用符
+ if (left == "") {
+ left = list[i], space = false, begin = i+1
+ } else if (left == list[i]) {
+ res.push({text: list.slice(begin, i), type: "string", left: left, right: left})
+ left = "", space = true, begin = i+1
+ }
+ } else if (sups[list[i]]) {
+ // 分隔符
+ if (left == "") {
+ if (!space) {
+ res.push(list.slice(begin, i))
+ }
+ res.push(list.slice(i, i+1))
+ space = true, begin = i+1
+ }
+ } else if (list[0] == '\\') {
+ // 转义符
+ for (var i = i; i < list.length-1; i++) {
+ list[i] = list[i+1]
+ }
+ list = list.slice(0, list.length-1)
+ space = false
+ } else {
+ space = false
+ }
+ }
+
+ // 末尾字符
+ if (left != "") {
+ res.push({text: list.slice(begin), type: "string", left: left, right: ""})
+ } else if (begin < list.length) {
+ res.push(list.slice(begin))
+ }
+ return res
+ },
+ parseJSON: function(str) { var res
+ if (typeof str == "object") { return str }
+ if (str.indexOf("http") == 0) { var ls = str.split("?")
+ res = {type: "link", name: "", text: str}
+ res.name = ls[0].split("://").pop().split("/")[0]
+ ls[1] && ls[1].split("&").forEach(function(item) { var ls = item.split("=")
+ res[decodeURIComponent(ls[0])] = decodeURIComponent(ls[1])
+ })
+ return res
+ }
+ try { res = JSON.parse(str)
+ res.text = res.text||str
+ res.type = res.type||"json"
+ } catch (e) {
+ res = {type: "text", text: str}
+ }
+ return res
},
}
diff --git a/publish/client/mp/utils/util.js b/publish/client/mp/utils/util.js
deleted file mode 100644
index 4149ac48..00000000
--- a/publish/client/mp/utils/util.js
+++ /dev/null
@@ -1,50 +0,0 @@
-const formatTime = date => {
- const year = date.getFullYear()
- const month = date.getMonth() + 1
- const day = date.getDate()
- const hour = date.getHours()
- const minute = date.getMinutes()
- const second = date.getSeconds()
-
- return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
-}
-
-const formatNumber = n => {
- n = n.toString()
- return n[1] ? n : '0' + n
-}
-function Number(d, n) {var res = [];
- while (d > 0) {res.push(d % 10); d = parseInt(d / 10); n--}
- while (n > 0) {res.push("0"); n--}
- return res.reverse(), res.join("");
-}
-function Time(t, fmt) {var now = t? new Date(t): new Date();
- fmt = fmt || "%y-%m-%d %H:%M:%S";
- fmt = fmt.replace("%y", now.getFullYear())
- fmt = fmt.replace("%m", Number(now.getMonth()+1, 2))
- fmt = fmt.replace("%d", Number(now.getDate(), 2))
- fmt = fmt.replace("%H", Number(now.getHours(), 2))
- fmt = fmt.replace("%M", Number(now.getMinutes(), 2))
- fmt = fmt.replace("%S", Number(now.getSeconds(), 2))
- return fmt
-}
-function Args(url, args) {var list = []
- for (var k in args) {
- list.push(encodeURIComponent(k)+"="+encodeURIComponent(args[k]))
- }
- return url+"?"+list.join("&")
-}
-
-module.exports = {
- formatTime: formatTime,
- Time: Time,
- Args: Args,
- List: function(list, cb) {
- var res = [], val;
- for (var i = 0; i < list.length; i++) {
- typeof cb == "function"? (val = cb(list[i], i, list)) != undefined && res.push(val): res.push(list[i])
-
- }
- return res
- },
-}