mirror of
https://shylinux.com/x/volcanos
synced 2025-04-25 16:58:06 +08:00
add template
This commit is contained in:
parent
ff0d27ee9b
commit
52c111234f
@ -6,11 +6,12 @@ App({
|
||||
request: function(cmd, data, cb) {var app = this; data.sessid = app.conf.sessid
|
||||
wx.request({method: "POST", url: app.conf.serve+"/"+cmd, data: data, success(res) {var msg = res.data
|
||||
console.log(msg)
|
||||
if (res.statusCode == 401) {delete(app.conf.userInfo)
|
||||
app.userinfo(function() {app.request(cmd, data, cb)})
|
||||
if (res.statusCode == 401) {
|
||||
app.usercode(function() {app.request(cmd, data, cb)})
|
||||
return
|
||||
}
|
||||
msg.__proto__ = {
|
||||
nRow() {return msg.append && msg.append[0] && msg[msg.append[0]].length || 0},
|
||||
Result() {return msg.result && msg.result.length > 0 && msg.result.join("") || ""},
|
||||
Table(cb) {var row = 0
|
||||
for (var i = 0; i < msg.append.length; i++) {
|
||||
@ -33,17 +34,25 @@ App({
|
||||
typeof cb == "function" && cb(res)
|
||||
}})
|
||||
},
|
||||
usercode: function(cb) {var app = this
|
||||
wx.login({success(res) {app.request("mp/login/code", {code: res.code}, function(msg) {
|
||||
wx.setStorage({key: "sessid", data: msg.Result()})
|
||||
app.conf.sessid = msg.Result(), typeof cb == "function" && cb()
|
||||
})}})
|
||||
},
|
||||
userinfo: function(cb) {var app = this
|
||||
if (app.conf.userInfo) {return typeof cb == "function" && cb(app.conf.userInfo)}
|
||||
wx.login({success(res) {app.request("mp/login/code", {code: res.code}, function(msg) {app.conf.sessid = msg.Result()
|
||||
app.usercode(function() {
|
||||
wx.getSetting({success(res) {res.authSetting['scope.userInfo'] && wx.getUserInfo({success(res) {
|
||||
app.request("mp/login/info", res.userInfo, function(msg) {app.conf.userInfo = res.userInfo, typeof cb == "function" && cb(res.userInfo)})
|
||||
}})}})
|
||||
})}})
|
||||
})
|
||||
},
|
||||
jumps: function(url, args, cb) {
|
||||
wx.navigateTo({url: utils.Args(url, args), success: cb})
|
||||
wx.navigateTo({url: "/pages/"+utils.Args(url, args), success: cb})
|
||||
},
|
||||
toast: function(title) {wx.showToast({title: title})},
|
||||
onLaunch: function() {},
|
||||
onLaunch: function() {
|
||||
this.conf.sessid = wx.getStorageSync("sessid")
|
||||
},
|
||||
})
|
||||
|
@ -5,7 +5,7 @@
|
||||
"pages/action/action",
|
||||
"pages/active/active",
|
||||
"pages/favor/favor",
|
||||
"pages/index/index"
|
||||
"pages/scans/scans"
|
||||
],
|
||||
"window": {
|
||||
"backgroundColor": "#000",
|
||||
|
5
client/mp/app.wxml
Normal file
5
client/mp/app.wxml
Normal file
@ -0,0 +1,5 @@
|
||||
<template name="list-name">
|
||||
<table wx:if="{{msg.append && msg.append[0]}}">
|
||||
<tr wx:for="{{msg[msg.append[0]]}}" bindtap="onClick" data-index="{{index}}"><td class="item">{{msg.name[index]}}</td></tr>
|
||||
</table>
|
||||
</template>
|
@ -31,3 +31,11 @@ td {
|
||||
text-align:center;
|
||||
border:solid 1px green;
|
||||
}
|
||||
td.item {
|
||||
font-size:18px;
|
||||
padding:10px;
|
||||
}
|
||||
|
||||
.output {
|
||||
border:solid 2px red;
|
||||
}
|
||||
|
@ -9,19 +9,43 @@ Page({
|
||||
{name: "清屏", bind: "refresh"},
|
||||
{name: "清空", bind: "refresh"},
|
||||
{name: "共享", bind: "refresh"},
|
||||
{name: "扫码", bind: "action"},
|
||||
],
|
||||
msg: {append: ["hi", "he"], hi: [1, 2], he: [3, 4]},
|
||||
res: [],
|
||||
his: {},
|
||||
},
|
||||
run: function(order, cb) {var page = this
|
||||
app.request("action", {cmds: [page.data.river, page.data.storm, order]}, function(msg) {
|
||||
run: function(order, cb) {var page = this, field = page.data.res[order]
|
||||
var his = page.data.his[order] || []
|
||||
var arg = []
|
||||
field.inputs.forEach(function(input) {
|
||||
if (input._input == "text") {
|
||||
arg.push(input.value||"")
|
||||
}
|
||||
})
|
||||
his.push(arg)
|
||||
page.data.his[order] = his
|
||||
|
||||
var cmds = [page.data.river, page.data.storm, order]
|
||||
field.inputs.forEach(function(input) {
|
||||
if (input._input == "text") {
|
||||
cmds.push(input.value||"")
|
||||
}
|
||||
})
|
||||
for (var i = cmds.length-1; i > 0; i--) {
|
||||
if (cmds[i] === "") {cmds.pop()} else {break}
|
||||
}
|
||||
app.request("action", {cmds: cmds}, function(msg) {
|
||||
page.data.res[order].msg = msg
|
||||
typeof cb == "function" && cb(msg)
|
||||
page.setData({res: page.data.res})
|
||||
typeof cb == "function" && cb(msg)
|
||||
})
|
||||
},
|
||||
action: function(event) {var page = this, name = event.target.dataset.name
|
||||
switch (name) {
|
||||
case "扫码":
|
||||
app.jumps("scans/scans")
|
||||
break
|
||||
case "串行":
|
||||
function cb(i) {
|
||||
page.run(i, function() {i < page.data.res.length && cb(i+1)})
|
||||
@ -33,32 +57,67 @@ Page({
|
||||
break
|
||||
}
|
||||
},
|
||||
refresh: function() {var page = this, data = []
|
||||
app.userinfo(function(userinfo) {
|
||||
refresh: function() {var page = this, data = []; page.data.his = {}
|
||||
app.data[page.data.river+page.data.storm] = page.data.res = data
|
||||
app.request("action", {cmds: [page.data.river, page.data.storm]}, function(msg) {
|
||||
msg.Table(function(line) {
|
||||
msg.Table(function(line, index) {
|
||||
line.feature = JSON.parse(line.feature)
|
||||
line.inputs = JSON.parse(line.inputs)
|
||||
if (!line.inputs || line.inputs.length === 0) {
|
||||
line.inputs = [{_input: "text"}, {_input: "button", value: "执行"}]
|
||||
}
|
||||
data.push(line)
|
||||
data.push(line), line.inputs.forEach(function(input) {
|
||||
input._input == "button" && input.action == "auto" && page.run(index)
|
||||
})
|
||||
page.setData({res: app.data[page.data.river+page.data.storm] = page.data.res = data})
|
||||
})
|
||||
page.setData({res: data})
|
||||
})
|
||||
},
|
||||
|
||||
onBlur: function(event) {var page = this, data = event.target.dataset
|
||||
page.data.res[data.order].inputs[data.index].value = event.detail.value
|
||||
},
|
||||
onFocus: function(event) {},
|
||||
onInput: function(event) {},
|
||||
onEnter: function(event) {var page = this, data = event.target.dataset
|
||||
console.log(event)
|
||||
page.data.res[data.order].inputs[data.index].value = event.detail.value
|
||||
},
|
||||
onClick: function(event) {var page = this, data = event.target.dataset
|
||||
var field = page.data.res[data.order]
|
||||
switch (data.input.cb) {
|
||||
case "Last":
|
||||
var his = page.data.his[data.order] || []
|
||||
his.pop()
|
||||
var arg = his.pop()
|
||||
if (arg) {
|
||||
field.inputs.forEach(function(input, i) {
|
||||
if (input._input == "text") {
|
||||
input.value = arg[i] || ""
|
||||
}
|
||||
})
|
||||
}
|
||||
page.data.his[data.order] = his
|
||||
default:
|
||||
this.run(event.target.dataset.order)
|
||||
}
|
||||
},
|
||||
onWhich: function(event) {var page = this, data = event.target.dataset
|
||||
page.data.res[data.order].inputs.forEach(function(input) {
|
||||
if (input.name == data.field) {
|
||||
input.value = data.value
|
||||
if (input.action == "auto") {
|
||||
page.run(data.order)
|
||||
}
|
||||
page.setData({res: page.data.res})
|
||||
}
|
||||
})
|
||||
},
|
||||
onClick: function(event) {this.run(event.target.dataset.order)},
|
||||
|
||||
onLoad: function (options) {var page = this
|
||||
app.conf.sessid = app.conf.sessid || options.sessid
|
||||
page.data.river = options.river
|
||||
page.data.storm = options.storm
|
||||
|
||||
var data = app.data[options.river+options.storm]
|
||||
if (data) {return page.setData({res: page.data.res = data})}
|
||||
this.refresh()
|
||||
|
@ -9,18 +9,19 @@
|
||||
<view><text class="title">{{field.name}}({{field.help}})</text></view>
|
||||
<view wx:for="{{field.inputs}}" class="inputs">
|
||||
<view wx:if="{{item._input == 'text'}}">
|
||||
<input type="text" placeholder="{{item.name}}" bindconfirm="onEnter" data-order="{{order}}" data-field="{{field}}"/>
|
||||
<input type="text" value="{{item.value}}" placeholder="{{item.name}}" bindblur="onBlur" bindconfirm="onEnter" data-order="{{order}}" data-index="{{index}}" data-item="{{item}}"/>
|
||||
</view>
|
||||
<view wx:elif="{{item._input == 'button'}}" class="button">
|
||||
<button size="mini" bindtap="onClick" data-order="{{order}}" data-field="{{field}}" data-index="{{index}}" data-input="{{item}}">{{item.value}}</button>
|
||||
<button size="mini" bindtap="onClick" data-order="{{order}}" data-field="{{field}}" data-index="{{index}}" data-input="{{item}}">{{item.value||item.name}}</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<table wx:if="{{field.msg}}">
|
||||
<tr><th wx:for="{{field.msg.append}}">{{item}}</th></tr>
|
||||
<tr wx:for="{{field.msg[field.msg.append[0]]}}" wx:for-index="line"><td wx:for="{{field.msg.append}}">{{field.msg[item][line]}}</td></tr>
|
||||
<tr wx:for="{{field.msg[field.msg.append[0]]}}" wx:for-index="line"><td wx:for="{{field.msg.append}}" bindtap="onWhich" data-value="{{field.msg[item][line]}}" data-index="{{line}}" data-field="{{item}}" data-order="{{order}}">{{field.msg[item][line]}}</td></tr>
|
||||
</table>
|
||||
<view class="output" wx:if="{{field.msg.result}}"><text wx:for="{{field.msg.result}}">{{item}}</text></view>
|
||||
<view class="output" wx:if="{{field.msg.result && field.feature && field.feature.display == 'inner'}}"><rich-text wx:for="{{field.msg.result}}" nodes="{{item}}"></rich-text></view>
|
||||
<view class="output" wx:elif="{{field.msg.result}}"><text wx:for="{{field.msg.result}}">{{item}}</text></view>
|
||||
</view>
|
||||
</view>
|
||||
|
@ -3,38 +3,30 @@ const app = getApp()
|
||||
|
||||
Page({
|
||||
data: {
|
||||
cmd: "",
|
||||
msg: {append: ["hi", "he"], hi: [1, 2], he: [3, 4]},
|
||||
msg: {append: ["key", "name"]},
|
||||
},
|
||||
refresh: function() {var page = this
|
||||
app.request("river", {}, function(msg) {page.setData({msg: msg})
|
||||
msg.nRow() == 1 && page.toStorm(0)
|
||||
})
|
||||
},
|
||||
|
||||
onClick: function(event) {var page = this, index = event.currentTarget.dataset.index
|
||||
app.jumps("/pages/storm/storm", {river: page.data.msg.key[index]})
|
||||
},
|
||||
toStorm: function(index) {app.jumps("storm/storm", {river: this.data.msg.key[index]})},
|
||||
|
||||
onFocus: function(event) {},
|
||||
onInput: function(event) {},
|
||||
onEnter: function(event) {var page = this
|
||||
app.userinfo(function(user) {
|
||||
app.request("mp/login/", {cmds: ["cmds", event.detail.value]}, function(msg) {
|
||||
page.setData({cmd: "", msg: msg})
|
||||
})
|
||||
})
|
||||
},
|
||||
onLoad: function (options) {var page = this
|
||||
app.userinfo(function(userinfo) {
|
||||
app.request("river", {}, function(msg) {
|
||||
page.setData({msg: msg})
|
||||
if (msg[msg.append[0]].length == 1) {
|
||||
app.jumps("/pages/storm/storm", {river: page.data.msg.key[0]})
|
||||
}
|
||||
})
|
||||
})
|
||||
onEnter: function(event) {},
|
||||
onClick: function(event) {this.toStorm(event.currentTarget.dataset.index)},
|
||||
|
||||
onLoad: function (options) {
|
||||
app.conf.sessid = app.conf.sessid || options.sessid
|
||||
this.refresh()
|
||||
},
|
||||
onReady: function () {},
|
||||
onShow: function () {
|
||||
},
|
||||
onShow: function () {},
|
||||
onHide: function () {},
|
||||
onUnload: function () {},
|
||||
onPullDownRefresh: function () {},
|
||||
onPullDownRefresh: function () {this.refresh()},
|
||||
onReachBottom: function () {},
|
||||
onShareAppMessage: function () {}
|
||||
})
|
||||
|
@ -1,5 +1,5 @@
|
||||
<import src="../../app.wxml"/>
|
||||
|
||||
<view class="display">
|
||||
<table wx:if="{{msg.append && msg.append[0]}}">
|
||||
<tr wx:for="{{msg[msg.append[0]]}}" wx:for-index="line" bindtap="onClick" data-index="{{line}}"><td>{{msg.name[line]}}</td></tr>
|
||||
</table>
|
||||
<template is="list-name" data="{{msg}}"></template>
|
||||
</view>
|
||||
|
@ -1,5 +0,0 @@
|
||||
td {
|
||||
font-size:18px;
|
||||
padding:10px;
|
||||
}
|
||||
|
@ -69,5 +69,6 @@ Page({
|
||||
}
|
||||
}})
|
||||
},
|
||||
|
||||
onLoad() {this.show()},
|
||||
})
|
@ -1,5 +1,6 @@
|
||||
.display {
|
||||
text-align:center;
|
||||
width:calc(100% - 40px);
|
||||
padding:20px;
|
||||
}
|
||||
.display button {
|
||||
@ -8,18 +9,12 @@
|
||||
.picture {
|
||||
border:solid 2px green;
|
||||
}
|
||||
view.content {
|
||||
.content {
|
||||
text-align:left;
|
||||
font-size:14px;
|
||||
color:gray;
|
||||
}
|
||||
textarea {
|
||||
height:45px;
|
||||
overflow:auto;
|
||||
border:solid 2px gray;
|
||||
width:calc(100% - 4px);
|
||||
}
|
||||
view.comment {
|
||||
.comment {
|
||||
text-align:left;
|
||||
font-size:14px;
|
||||
color:gray;
|
||||
@ -27,3 +22,10 @@ view.comment {
|
||||
.output {
|
||||
text-align:center;
|
||||
}
|
||||
|
||||
textarea {
|
||||
height:45px;
|
||||
overflow:auto;
|
||||
border:solid 2px gray;
|
||||
width:calc(100% - 4px);
|
||||
}
|
@ -3,40 +3,29 @@ const app = getApp()
|
||||
|
||||
Page({
|
||||
data: {
|
||||
cmd: "",
|
||||
river: "",
|
||||
msg: {append: ["hi", "he"], hi: [1, 2], he: [3, 4]},
|
||||
river: "", msg: {append: ["key", "name"]},
|
||||
},
|
||||
refresh: function() {var page = this
|
||||
app.request("storm", {cmds: [page.data.river]}, function(msg) {
|
||||
page.setData({msg: msg}), msg.nRow() == 1 && page.toAction(0)
|
||||
})
|
||||
},
|
||||
toAction: function(index) {app.jumps("action/action", {river: this.data.river, storm: this.data.msg.key[index]})},
|
||||
|
||||
onClick: function(event) {var page = this, index = event.currentTarget.dataset.index
|
||||
app.jumps("/pages/action/action", {river: page.data.river, storm: page.data.msg.key[index]})
|
||||
},
|
||||
onFocus: function(event) {},
|
||||
onInput: function(event) {},
|
||||
onEnter: function(event) {var page = this
|
||||
app.userinfo(function(user) {
|
||||
app.request("mp/login/", {cmds: ["cmds", event.detail.value]}, function(msg) {
|
||||
page.setData({cmd: "", msg: msg})
|
||||
})
|
||||
})
|
||||
},
|
||||
onLoad: function (options) {var page = this
|
||||
page.data.river = options.river
|
||||
app.userinfo(function(userinfo) {
|
||||
app.request("storm", {cmds: [options.river]}, function(msg) {
|
||||
page.setData({msg: msg})
|
||||
if (msg[msg.append[0]].length == 1) {
|
||||
app.jumps("/pages/action/action", {river: options.river, storm: page.data.msg.key[0]})
|
||||
}
|
||||
})
|
||||
})
|
||||
onEnter: function(event) {},
|
||||
onClick: function(event) {this.toAction(event.currentTarget.dataset.index)},
|
||||
|
||||
onLoad: function (options) {
|
||||
app.conf.sessid = app.conf.sessid || options.sessid
|
||||
this.data.river = options.river, this.refresh()
|
||||
},
|
||||
onReady: function () {},
|
||||
onShow: function (args) {
|
||||
},
|
||||
onShow: function (args) {},
|
||||
onHide: function () {},
|
||||
onUnload: function () {},
|
||||
onPullDownRefresh: function () {},
|
||||
onPullDownRefresh: function () {this.refresh()},
|
||||
onReachBottom: function () {},
|
||||
onShareAppMessage: function () {}
|
||||
})
|
||||
|
@ -1,5 +1,5 @@
|
||||
<import src="../../app.wxml"/>
|
||||
|
||||
<view class="display">
|
||||
<table wx:if="{{msg.append && msg.append[0]}}">
|
||||
<tr wx:for="{{msg[msg.append[0]]}}" wx:for-index="line" bindtap="onClick" data-index="{{line}}"><td>{{msg.name[line]}}</td></tr>
|
||||
</table>
|
||||
<template is="list-name" data="{{msg}}"></template>
|
||||
</view>
|
||||
|
@ -1,4 +0,0 @@
|
||||
td {
|
||||
font-size:18px;
|
||||
padding:10px;
|
||||
}
|
@ -33,13 +33,50 @@
|
||||
"current": -1,
|
||||
"list": []
|
||||
},
|
||||
"plugin": {
|
||||
"current": -1,
|
||||
"list": []
|
||||
},
|
||||
"game": {
|
||||
"currentL": -1,
|
||||
"list": []
|
||||
},
|
||||
"miniprogram": {
|
||||
"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": "pages/storm/storm",
|
||||
"pathName": "pages/storm/storm",
|
||||
"query": "river=c796cd&storm=9092d5",
|
||||
"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
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user