forked from x/ContextOS
opt list
This commit is contained in:
parent
24220fd9dc
commit
399bfd20bd
@ -1,32 +1,73 @@
|
||||
App({
|
||||
log: function(type, args) {
|
||||
console[type](args)
|
||||
},
|
||||
toast: function(text) {
|
||||
wx.showToast()
|
||||
},
|
||||
place: function(cb) {
|
||||
var app = this
|
||||
wx.authorize({scope: "scope.userLocation"})
|
||||
|
||||
wx.chooseLocation({success: function(res) {
|
||||
app.log("info", res)
|
||||
typeof cb == "function" && cb(res)
|
||||
}})
|
||||
},
|
||||
navigate: function(page, args) {
|
||||
if (!page) {
|
||||
wx.navigateBack()
|
||||
return
|
||||
}
|
||||
var list = []
|
||||
for (var k in args) {
|
||||
list.push(k+"="+args[k])
|
||||
}
|
||||
|
||||
wx.navigateTo({url:"/pages/"+page+"/"+page + (list.length>0? "?"+list.join("&"): "")})
|
||||
},
|
||||
|
||||
request: function(data, done, fail) {
|
||||
var app = this
|
||||
data = data || {}
|
||||
data.sessid = app.sessid || ""
|
||||
|
||||
wx.request({method: "POST", url: "https://shylinux.com/chat/mp", data: data,
|
||||
var what = {method: "POST", url: "https://shylinux.com/chat/mp", data: data,
|
||||
success: function(res) {
|
||||
what.res = res
|
||||
app.log("info", what)
|
||||
typeof done == "function" && done(res.data)
|
||||
},
|
||||
fail: function(res) {
|
||||
what.res = res
|
||||
app.log("info", what)
|
||||
typeof done == "function" && done(res.data)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
wx.request(what)
|
||||
},
|
||||
|
||||
sessid: "",
|
||||
userInfo: {},
|
||||
login: function(cb) {
|
||||
var app = this
|
||||
wx.login({success: res => {
|
||||
if (app.sessid) {
|
||||
typeof cb == "function" && cb(app.userInfo)
|
||||
return
|
||||
}
|
||||
|
||||
wx.login({success: function(res) {
|
||||
app.request({code: res.code}, function(sessid) {
|
||||
app.sessid = sessid
|
||||
|
||||
wx.getSetting({success: res => {
|
||||
wx.getSetting({success: function(res) {
|
||||
if (res.authSetting['scope.userInfo']) {
|
||||
wx.getUserInfo({success: res => {
|
||||
wx.getUserInfo({success: function(res) {
|
||||
app.userInfo = res.userInfo
|
||||
app.request(res, cb)
|
||||
app.request(res, function() {
|
||||
typeof cb == "function" && cb(app.userInfo)
|
||||
})
|
||||
}})
|
||||
}
|
||||
}})
|
||||
@ -34,11 +75,82 @@ App({
|
||||
}})
|
||||
},
|
||||
|
||||
onLaunch: function () {
|
||||
command: function(args, cb) {
|
||||
var app = this
|
||||
this.login(function() {
|
||||
app.request({"cmd": ["note", "model"]})
|
||||
|
||||
app.login(function(userInfo) {
|
||||
app.request({cmd: ["context", "ssh", "sh", "node", "note", "context", "mdb"].concat(args["cmd"])}, function(res) {
|
||||
app.toast("ok")
|
||||
typeof cb == "function" && cb(res)
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
model: {},
|
||||
data: {model: {}, list: []},
|
||||
load: function(type, cb) {
|
||||
var app = this
|
||||
switch (type) {
|
||||
case "model":
|
||||
if (app.data.length > 0 && app.data.model.length > 0) {
|
||||
typeof cb == "function" && cb(app.data.model)
|
||||
return
|
||||
}
|
||||
|
||||
var cmd = {"cmd": ["note", type]}
|
||||
if (type == "note") {
|
||||
cmd.cmd.push("note")
|
||||
}
|
||||
|
||||
app.command(cmd, function(res) {
|
||||
var ncol = res.append.length
|
||||
var nrow = res[res.append[0]].length
|
||||
for (var i = 0; i < nrow; i++) {
|
||||
app.data.model[res["name"][i]] = {
|
||||
name: res["name"][i],
|
||||
data: JSON.parse(res["data"][i] || "[]"),
|
||||
view: JSON.parse(res["view"][i] || "{}"),
|
||||
}
|
||||
}
|
||||
typeof cb == "function" && cb(app.data.model)
|
||||
})
|
||||
break
|
||||
case "list":
|
||||
if (app.data.length > 0 && app.data.list.length > 0) {
|
||||
typeof cb == "function" && cb(app.data.list)
|
||||
return
|
||||
}
|
||||
|
||||
var cmd = {"cmd": ["note", "search", "username"]}
|
||||
|
||||
app.command(cmd, function(res) {
|
||||
if (!res || !res.append) {
|
||||
return
|
||||
}
|
||||
|
||||
var ncol = res.append.length
|
||||
var nrow = res[res.append[0]].length
|
||||
for (var i = 0; i < nrow; i++) {
|
||||
var args = {}
|
||||
var value = JSON.parse(res["value"][i] || "[]")
|
||||
for (var j = 0; j < value.length; j++) {
|
||||
args[value[j].name] = value[j].value
|
||||
}
|
||||
|
||||
app.data.list.push({
|
||||
create_date: res["create_time"][i].split(" ")[0].replace("-", "/").replace("-", "/"),
|
||||
create_time: res["create_time"][i],
|
||||
model: res["model"][i],
|
||||
name: res["name"][i],
|
||||
value: value,
|
||||
args: args,
|
||||
view: JSON.parse(res["view"][i] || "{}"),
|
||||
})
|
||||
}
|
||||
typeof cb == "function" && cb(app.data.list)
|
||||
})
|
||||
break
|
||||
}
|
||||
},
|
||||
|
||||
onLaunch: function () {},
|
||||
})
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"pages": [
|
||||
"pages/index/index",
|
||||
"pages/list/list",
|
||||
"pages/index/index",
|
||||
"pages/note/note"
|
||||
],
|
||||
"window": {
|
||||
|
@ -2,6 +2,7 @@ const app = getApp()
|
||||
|
||||
Page({
|
||||
data: {
|
||||
focus: false,
|
||||
cmd: "",
|
||||
table: [],
|
||||
append: [],
|
||||
@ -9,7 +10,8 @@ Page({
|
||||
},
|
||||
onCommand: function(e) {
|
||||
var page = this
|
||||
app.request({"cmd": e.detail.value}, function(res) {
|
||||
var cmd = e.detail.value
|
||||
app.command({"cmd": cmd}, function(res) {
|
||||
if (res.append) {
|
||||
var table = []
|
||||
for (var i = 0; i < res[res.append[0]].length; i++) {
|
||||
@ -24,7 +26,29 @@ Page({
|
||||
page.setData({append: [], table: []})
|
||||
}
|
||||
page.setData({result: res.result? res.result.join("") :res})
|
||||
if (page.data.cmd) {
|
||||
return
|
||||
}
|
||||
app.command({"cmd": ["note", cmd, "flow", cmd]}, function(res) {})
|
||||
})
|
||||
},
|
||||
onLoad: function (options) {
|
||||
app.log("info", {page: "pages/index/index", options: options})
|
||||
|
||||
var page = this
|
||||
app.load("model", function(model) {
|
||||
app.log("info", app.data.list[options.index])
|
||||
var cmd = app.data.list[options.index]? app.data.list[options.index].args["cmd"]: ""
|
||||
page.setData({
|
||||
model: model[options.model],
|
||||
value: app.data.list[options.index],
|
||||
view: model[options.model].view,
|
||||
cmd: cmd,
|
||||
focus: cmd? false: true,
|
||||
})
|
||||
if (cmd) {
|
||||
page.onCommand({detail:{value:cmd}})
|
||||
}
|
||||
})
|
||||
},
|
||||
onLoad: function () {},
|
||||
})
|
||||
|
@ -1,6 +1,6 @@
|
||||
<view class="container">
|
||||
<view class="input">
|
||||
<input class="command" type="text" bindconfirm="onCommand" confirm-hold="true" focus="true"/>
|
||||
<input class="command" type="text" value="{{cmd}}" bindconfirm="onCommand" confirm-hold="true" focus="{{focus}}"/>
|
||||
</view>
|
||||
<scroll-view scroll-y class="table">
|
||||
<view class="table-th" wx:for="{{append}}">{{item}}</view>
|
||||
|
@ -37,12 +37,20 @@
|
||||
"list": []
|
||||
},
|
||||
"miniprogram": {
|
||||
"current": 0,
|
||||
"current": 1,
|
||||
"list": [
|
||||
{
|
||||
"id": -1,
|
||||
"id": 0,
|
||||
"name": "note",
|
||||
"pathName": "pages/note/note",
|
||||
"query": "model=note",
|
||||
"scene": null
|
||||
},
|
||||
{
|
||||
"id": -1,
|
||||
"name": "list",
|
||||
"pathName": "pages/list/list",
|
||||
"query": "",
|
||||
"scene": null
|
||||
}
|
||||
]
|
||||
|
Loading…
x
Reference in New Issue
Block a user