1
0
mirror of https://shylinux.com/x/ContextOS synced 2025-04-26 09:14:06 +08:00

mix branch 'master' of github.com:shylinux/context

This commit is contained in:
shylinux 2019-03-11 09:22:34 +08:00
commit ecc667f4ea
5 changed files with 199 additions and 68 deletions

View File

@ -1,19 +1,41 @@
App({ App({
log: function(type, args) { log: function(type, args) {
console[type](args) switch (type) {
case "info":
console.log(args)
break
default:
console.log(type, args)
}
}, },
toast: function(text) { toast: function(text) {
wx.showToast() wx.showToast(text)
},
sheet: function(list, cb) {
wx.showActionSheet({itemList: list, success(res) {
typeof cb == "function" && cb(list[res.tapIndex])
}})
},
confirm: function(content, confirm, cancel) {
wx.showModal({
title: "context", content: content, success: function(res) {
res.confirm && typeof confirm == "function" && confirm()
res.cancel && typeof cancel == "function" && cancel()
}
})
}, },
place: function(cb) { place: function(cb) {
var app = this var app = this
wx.authorize({scope: "scope.userLocation"}) wx.authorize({scope: "scope.userLocation"})
wx.chooseLocation({success: function(res) { wx.chooseLocation({success: function(res) {
app.log("info", res) app.log(res)
typeof cb == "function" && cb(res) typeof cb == "function" && cb(res)
}}) }})
}, },
stoprefresh: function(cb) {
wx.stopPullDownRefresh()
},
navigate: function(page, args) { navigate: function(page, args) {
if (!page) { if (!page) {
wx.navigateBack() wx.navigateBack()
@ -35,12 +57,12 @@ App({
var what = {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) { success: function(res) {
what.res = res what.res = res
app.log("info", what) app.log(what)
typeof done == "function" && done(res.data) typeof done == "function" && done(res.data)
}, },
fail: function(res) { fail: function(res) {
what.res = res what.res = res
app.log("info", what) app.log(what)
typeof done == "function" && done(res.data) typeof done == "function" && done(res.data)
}, },
} }
@ -89,6 +111,19 @@ App({
}) })
}) })
}, },
table: function(res, cb) {
if (res.append) {
for (var i = 0; i < res[res.append[0]].length; i++) {
var obj = {}
var line = []
for (var j = 0; j < res.append.length; j++) {
line.push(res[res.append[j]][i])
obj[res.append[j]] = res[res.append[j]][i]
}
typeof cb == "function" && cb(i, obj, line)
}
}
},
model: {}, model: {},
data: {model: {}, list: []}, data: {model: {}, list: []},
@ -110,12 +145,18 @@ App({
var ncol = res.append.length var ncol = res.append.length
var nrow = res[res.append[0]].length var nrow = res[res.append[0]].length
for (var i = 0; i < nrow; i++) { for (var i = 0; i < nrow; i++) {
app.data.model[res["name"][i]] = { var view = JSON.parse(res["view"][i] || "{}")
name: res["name"][i], var data = JSON.parse(res["data"][i] || "[]")
data: JSON.parse(res["data"][i] || "[]"), data.unshift({"name": "model", "type": "text", "value": res["name"][i]})
view: JSON.parse(res["view"][i] || "{}"), data.unshift({"name": "name", "type": "text"})
if (view.edit) {
for (var j = 0; j < data.length; j++) {
data[j].view = view.edit[data[j].name]
} }
} }
app.data.model[res["name"][i]] = {name: res["name"][i], data: data, view: view}
}
typeof cb == "function" && cb(app.data.model) typeof cb == "function" && cb(app.data.model)
}) })
break break
@ -125,37 +166,53 @@ App({
return return
} }
var cmd = {"cmd": ["note", "search", "username"]} var cmd = {"cmd": ["note", "show", "username", "username", "full"]}
app.command(cmd, function(res) { app.command(cmd, function(res) {
if (!res || !res.append) { if (!res || !res.append) {
return return
} }
var list = []
var ncol = res.append.length var ncol = res.append.length
var nrow = res[res.append[0]].length var nrow = res[res.append[0]].length
for (var i = 0; i < nrow; i++) { for (var i = 0; i < nrow; i++) {
var args = {}
var value = JSON.parse(res["value"][i] || "[]") var value = JSON.parse(res["value"][i] || "[]")
for (var j = 0; j < value.length; j++) { value.unshift({"type": "text", "name": "model", "value": res["model"][i]})
args[value[j].name] = value[j].value value.unshift({"type": "text", "name": "name", "value": res["name"][i]})
value.unshift({"type": "text", "name": "create_date", "value": res["create_time"][i].split(" ")[0].replace("-", "/").replace("-", "/")})
var line = {
create_time: res["create_time"][i],
model: res["model"][i], value: value,
view: JSON.parse(res["view"][i] || "{}"), data: {},
} }
app.data.list.push({ for (var v in line.view) {
create_date: res["create_time"][i].split(" ")[0].replace("-", "/").replace("-", "/"), var view = line.view[v]
create_time: res["create_time"][i],
model: res["model"][i], var data = []
name: res["name"][i], for (var k in view) {
value: value, if (k in line) {
args: args, data.push({name: k, view: view[k], value: line[k]})
view: JSON.parse(res["view"][i] || "{}"),
})
} }
typeof cb == "function" && cb(app.data.list) }
for (var j = 0; j < value.length; j++) {
var k = value[j]["name"]
if (((v == "edit") || (k in view)) && !(k in line)) {
data.push({name: k, view: view[k] || "", value: value[j]["value"]})
}
}
line.data[v] = data
}
list.push(line)
}
app.data.list = list
typeof cb == "function" && cb(list)
}) })
break break
} }
}, },
onLaunch: function () {},
}) })

View File

@ -11,7 +11,8 @@
"backgroundTextStyle": "light", "backgroundTextStyle": "light",
"navigationBarBackgroundColor": "#000", "navigationBarBackgroundColor": "#000",
"navigationBarTitleText": "context", "navigationBarTitleText": "context",
"navigationBarTextStyle": "white" "navigationBarTextStyle": "white",
"enablePullDownRefresh": true
}, },
"permission": { "permission": {
"scope.userLocation": { "scope.userLocation": {

View File

@ -2,53 +2,120 @@ const app = getApp()
Page({ Page({
data: { data: {
focus: false, nodes: [
cmd: "", ["note", "shy"],
table: [], ["ctx", "cmd"],
append: [], ["note", "show"],
result: "", ],
shows: [0, 0, 0],
ctx: "", cmd: "", focus: false,
append: [], table: [], result: "",
},
getPod(cb) {
var page = this
app.command({"cmd": ["context", "ssh", "remote"]}, function(res) {
var pod = [""]
app.table(res, function(i, obj, line) {
pod.push(obj.key)
})
page.data.nodes[0] = pod
page.data.shows[0] = 0
page.setData({nodes: page.data.nodes, shows: page.data.shows})
typeof cb == "function" && cb(pod)
})
},
getCtx(pod, cb) {
var page = this
app.command({"cmd": ["context", "ssh", "sh", pod, "context", "ctx", "context"]}, function(res) {
var ctx = []
app.table(res, function(i, obj, line) {
ctx.push(obj.names)
})
page.data.nodes[1] = ctx
page.data.shows[1] = 0
page.setData({nodes: page.data.nodes, shows: page.data.shows})
typeof cb == "function" && cb(ctx)
})
},
getCmd(pod, ctx, cb) {
var page = this
app.command({"cmd": ["context", "ssh", "sh", pod, "context", ctx, "command", "all"]}, function(res) {
var cmd = [""]
app.table(res, function(i, obj, line) {
cmd.push(obj.key)
})
page.data.nodes[2] = cmd
page.data.shows[2] = 0
page.setData({nodes: page.data.nodes, shows: page.data.shows})
page.setData({ctx: "context ssh sh node '"+pod+"' context "+ctx+" "+cmd[0]})
typeof cb == "function" && cb(cmd)
})
},
onChange: function(e) {
var column = e.detail.column
var value = e.detail.value
var page = this
page.data.shows[column] = value
var pod = page.data.nodes[0][page.data.shows[0]]
var ctx = page.data.nodes[1][page.data.shows[1]]
var cmd = page.data.nodes[2][page.data.shows[2]]
switch (column) {
case 0:
page.getCtx(pod, function(ctx) {
page.getCmd(pod, ctx[0], function(cmd) {
this.onCommand({detail:{value: ""}})
})
})
break
case 1:
page.getCmd(pod, ctx, function(cmd) {
this.onCommand({detail:{value: ""}})
})
break
case 2:
page.setData({ctx: "context ssh sh node '"+pod+"' context "+ctx+" "+cmd})
this.onCommand({detail:{value: ""}})
break
}
}, },
onCommand: function(e) { onCommand: function(e) {
var page = this
var cmd = e.detail.value var cmd = e.detail.value
app.command({"cmd": ["source", cmd]}, function(res) { var page = this
if (res.append) { app.command({"cmd": ["source", page.data.ctx, cmd]}, function(res) {
var table = [] var table = []
for (var i = 0; i < res[res.append[0]].length; i++) { app.table(res, function(i, obj, line) {
var line = []
for (var j = 0; j < res.append.length; j++) {
line.push(res[res.append[j]][i])
}
table.push(line) table.push(line)
} })
page.setData({append: res.append, table: table})
} else { page.setData({append: res.append || [], table: table, result: res.result? res.result.join("") :res})
page.setData({append: [], table: []})
}
page.setData({result: res.result? res.result.join("") :res})
if (page.data.cmd) { if (page.data.cmd) {
return return
} }
app.command({"cmd": ["note", cmd, "flow", cmd]}, function(res) {}) app.command({"cmd": ["note", cmd, "proxy", page.data.ctx, cmd]})
}) })
}, },
onLoad: function (options) { onLoad: function (options) {
app.log("info", {page: "pages/index/index", options: options}) app.log({page: this.route, options: options})
var data = app.data.list[options.index]
var cmd = ""
var page = this var page = this
app.load("model", function(model) { page.getPod(function(pod) {
app.log("info", app.data.list[options.index]) page.getCtx(pod[0], function(ctx) {
var cmd = app.data.list[options.index]? app.data.list[options.index].args["cmd"]: "" page.getCmd(pod[0], ctx[0], function(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}}) })
if (data) {
for (var i = 0; i < data.value.length; i++) {
if (data.value[i].name == "cmd") {
cmd = data.value[i].value
this.onCommand({detail:{value: cmd}})
} }
}) }
}
this.setData({cmd: cmd, focus: cmd? false: true})
}, },
}) })

View File

@ -1,10 +1,16 @@
<view class="container"> <view class="page">
<picker
mode="multiSelector" range="{{nodes}}" value="{{shows}}"
bindchange="onChange" bindcolumnchange="onChange">
<view class="input">{{ctx}}</view>
</picker>
<view class="input"> <view class="input">
<input class="command" type="text" value="{{cmd}}" bindconfirm="onCommand" confirm-hold="true" focus="{{focus}}"/> <input class="command" type="text" value="{{cmd}}" bindconfirm="onCommand" confirm-hold="true" focus="{{focus}}"/>
</view> </view>
<scroll-view scroll-y class="table"> <scroll-view class="table" scroll-y>
<view class="table-th" wx:for="{{append}}">{{item}}</view> <view wx:for="{{append}}" class="table-th">{{item}}</view>
<view class="table-row" wx:for="{{table}}"><view class="table-td" wx:for="{{item}}">{{item}}</view></view> <view wx:for="{{table}}" class="table-row"><view wx:for="{{item}}" class="table-td">{{item}}</view></view>
</scroll-view> </scroll-view>
<view class="result">{{result}}</view> <view class="result">{{result}}</view>
</view> </view>

View File

@ -1,9 +1,10 @@
.container { .page {
color:cyan; color:cyan;
font-size:16px; font-size:16px;
font-family:Courier; font-family:Courier;
background-color:black; background-color:black;
min-height:800px; min-height:800px;
overflow:auto;
} }
.command { .command {
border:solid 2px green; border:solid 2px green;
@ -13,7 +14,6 @@
border:solid 1px green; border:solid 1px green;
display:table; display:table;
overflow:auto; overflow:auto;
max-width:100%;
} }
.table-row { .table-row {
display:table-row; display:table-row;