一些常用的方法集合
设置点击事件
function backClicked()
ui:tip('点击显示')
end
ui:setClickEvent('cid_back', 'backClicked');
页面返回方法
function backClicked()
ui:closeDialog()
end
ui:setClickEvent('cid_back', 'backClicked');
异步请求通信
function tbCLickSync()
local itIn = CIntent();
itIn:set("file", "test");
itIn:set("cmd", "test");
ui:showLoadingDialog()
db:execCmdSync(itIn, function(outIt)
ui:tip(outIt:toString())
ui:dismissDialog()
end )
end
扫码控件事件
function process_barcode(sType,sBarCode)
if sType == 1000 then
ui:tip(sBarCode)
return
end
end
ui:setScanBarcode('et_box_code', 1000)
获取扫码控件值
ui:get('result'):value()
弹出是否选择对话框
function tbTestOpenYesOrNo()
local sInfo = string.format('确认报工?\n报废数量:%s',123);
ui:msg(sInfo, function(tag)
if tag then
end
end);
end
设置系统当天日期
local now = os.date('%Y-%m-%d')
ui:set('et_date', now)
选择日期
ui:proxyCreateYYYYMMDDdialog(function(val)
ui:set('et_date', val)
end)
弹出选择框
function tbPopClicked()
local help = CSelectHelp();
help:addField('code');
help:addField('name');
local line = CVector();
line:push_back('0');
line:push_back('未开始');
help:addVectorValue(line);
line:clear();
line:push_back('1');
line:push_back('加工中');
help:addVectorValue(line);
ui:proxyCreateSingleChoiceDialog(help, 'name', function(row)
local title = help:vs(row, 'name')
ui:set('et_select', title)
end)
end
聚焦扫码输入控件
ui:get("et_eqpt_code"):focusable(true)
动态设置listView控件高度
ui:get('list_view'):flexCss("height: " .. sys.contH - 110 - 60 - 44 * 2)
listView中事件、数据绑定
local helpCache = CSelectHelp();
helpCache:addField('id');
helpCache:addField('info');
helpCache:addField('check');
local line = CVector();
for i = 0, 20 do
line:clear()
line:push_back(i);
line:push_back('信息:');
line:push_back('false')
helpCache:addVectorValue(line);
end
ui:bindListViewListener('id_android_list_collectionview_001', sys.contW, -2, helpCache,'app2_cell.xml',
'showListView', 'onItemClick')
function showListView(cell, section, row)
end
function onItemClick(cell, section, row)
local check = helpCache:vs(row, 'check')
if check == 'false' then
cell.objs["tv_info"]:textColor(0xbd183a)
helpCache:setValueString(row, 'check', 'true')
else
cell.objs["tv_info"]:textColor(0x000000)
helpCache:setValueString(row, 'check', 'false')
end
end
页面跳转传值
function tbTest1Clicked_bak()
local itIn = CIntent();
itIn:set("test1", "value1");
local helpTmp = CSelectHelp()
helpTmp:addField('id')
helpTmp:addField('info')
local line = CVector()
line:push_back('1')
line:push_back('okok')
helpTmp:addVectorValue(line)
itIn:setHelp('help', helpTmp)
ui:onFragmentShowSimpleActivity('meida_quality_list', itIn, 3000, 'selectCallback')
end
function selectCallback(requestCode, sInfo)
if requestCode == 3000 then
local inIt = CIntent()
inIt:fromString(sInfo)
local helpTmp = CSelectHelp()
inIt:getHelp('help',helpTmp)
ui:tip(helpTmp:toString())
return
end
end
接收页面处理
local helpTmp = CSelectHelp()
local other_page_var = ui:getDialogVar('test1');
ui:getDialogHelp('help', helpTmp)
function tbSaveClicked()
local itIn = CIntent();
itIn:set('param1', 'test')
itIn:setHelp('help', helpTmp)
ui:setReturnResult(itIn:toString())
ui:closeDialog()
end
开发时调试代码段
function tbSaveClicked()
local itIn = CIntent();
itIn:set('param1', 'test')
itIn:setHelp('help', helpTmp)
ui:setReturnResult(itIn:toString())
ui:closeDialog()
end
ui:debug('tbSaveClicked')
动态改变显示的Y坐标
ui:get('id_contain_code'):hide(true)
local translate = Animation():translationY(-45):duration(0)
translate:with(ui:get('id_user_cn_name')):start()
短暂显示后消失
ui:showToastDialog()
ui:showToastDialog('成功')
ui:showToastDialog('失败', 'FINISH')
ui:showToastDialog('失败', 'ERROR')
ui:showToastDialog('警告', 'WARN')
主菜单页面显示横/竖屏设置
在数据库android菜单表的app_orientation字段,0值为横屏,1值为竖屏
若数据结构不同,请参照最新的数据库结构:app.zjtouchnet.com 2014 tn_iot_v3数据库中的表结构
代码调用其它页面设置显示横/竖屏设置
local itIn = CIntent();
itIn:set('app_orientation', '0')
ui:onFragmentShowSimpleActivity('app3', itIn, 3000, 'selectCallback')
调用上传图片UI及回调接收示例
function selectCallback(requestCode, sInfo)
if requestCode == 4000 then
m_helpPicture:fromString(sInfo)
ui:set('img',m_helpPicture:vs(0,'qc_d_flow_files'))
return
end
end
function click_upload_btn()
local itIn = CIntent()
itIn:set('file', 'hl_lab_qc')
itIn:set('cmd', 'upload_picture')
itIn:set('file_path','')
itIn:set('file_size', '')
itIn:set('old_file', m_helpPicture:vs(0,'qc_d_flow_files'))
local uiParam = CIntent()
uiParam:set('title', '上传图片列表')
uiParam:set('remote_path', '/lab_qc/picture/')
ui:getPictureActivity(itIn, uiParam, 4000, m_helpPicture,'selectCallback')
end
mqtt接口通信格式
{
"id":"****",
"code":"1",
"error":"无错误信息",
"send_date":"",
"level":"error",
"from":"",
"to":"",
"type":"normal",
"title":"",
"msg":"", ,
"ext":{
"cid":"",
"type":"lua",
"url":"http://m.baidu.com",
"recive_callback_file":"",
"recive_callback_cmd":"",
"recive_callback_ext":"",
}
}
{
"id":"100000000",
"code": "1",
"error": "无错误信息",
"send_date": "2020-11-11 10:00:00",
"level": "error",
"from": "",
"to": "",
"type": "normal",
"title": "压铸设备A异常",
"msg": "收不到产出信号,需具体排查",
"ext": {
"cid": "",
"type": "url",
"url":"http://m.baidu.com",
"recive_callback_file":"test",
"recive_callback_cmd":"test",
"recive_callback_ext":""
}
}
serv:sendMqtt('/common','接口格式json字符串');
serv:sendMqtt('/userId/1111','接口格式json字符串');