unknown 1 anno fa
parent
commit
96129d1bd8
8 ha cambiato i file con 659 aggiunte e 0 eliminazioni
  1. 133 0
      _entry.js
  2. 133 0
      _entry_preview.js
  3. 122 0
      js/_model.js
  4. 101 0
      js/mainfrm_pane.js
  5. 7 0
      js/module/database.js
  6. BIN
      js/名单.xlsx
  7. 11 0
      kul/kul.entry.xml
  8. 152 0
      kul/mainfrm.kul

+ 133 - 0
_entry.js

@@ -0,0 +1,133 @@
+var fs = require('fs');
+var vm = require('vm');
+
+initRuntimeEnv();
+
+var dirHome = process.env['COMX_SDK'];
+var dirUnit = __dirname + '/';
+
+if(process.platform == 'win32')
+{
+    require('bindings')('js_ext_comx_qtshell-native-win.node');
+    require('bindings')('js_ext_comx_resource-native-win.node');
+    require('bindings')('js_ext_comx_mutex-native-win.node');
+}
+
+if(process.platform == 'linux')
+{
+    require('bindings')('js_ext_comx_qt-native-linux.node');
+    require('bindings')('js_ext_comx_resource-native-linux.node');
+    require('bindings')('js_ext_comx_mutex-native-linux.node');
+}
+
+var require_ = require('require-from-string');
+var __ = (_)=>{
+    (new vm.Script(_)).runInNewContext({
+	'require' : require,
+	'process' : process,
+	'comx' : comx,
+	'exports' :exports,
+	'comx_startup' : ()=>{
+	    comx.resource.qt.loadUnit(dirUnit, exports, function(){
+		if(process.argv.length >= 3)
+		    unit.form[process.argv[2]].Show();
+		else
+		    unit.form._entry.Show();
+	    }, (form)=>{
+		//readyForm
+	    });
+	}
+    });
+};
+
+var tmpl = fs.readFileSync(dirHome+'template/4e7b90182d3b4e11a7ca74d8fc8c545f');
+comx.resource.Initialize(require_, __, tmpl);
+
+if(!comx.resource.hasResource)
+{
+    if(process.argv.length == 4)
+    {
+	var tmpl = fs.readFileSync(dirHome+'template/008f111453704f82b9616e9bf92655f0');
+	comx.resource.LoadKernelRemote(parseInt(process.argv[3]), false, tmpl);
+    }
+    else
+    {
+	var tmpl = fs.readFileSync(dirHome+'template/ad72fee60eea4a89844aa934b9bc099b');
+	comx.resource.LoadKernelRemote(getWSAddress(), false, tmpl);
+    }
+}
+else
+{
+    comx.resource.qt.loadUnit(dirUnit, exports, function(){
+	if(process.argv.length >= 3)
+	    unit.form[process.argv[2]].Show();
+	else
+	    unit.form._entry.Show();
+    }, (form)=>{
+	//readyForm
+    });
+}
+
+process.on('uncaughtException', (e)=>{
+    console.error('process error is:', e.message);
+});
+
+/////////////////////////////////////////////////////////////////////////////
+// Init Runtime Env
+
+function initRuntimeEnv()
+{
+    process.env.COMX_SDK = getHomeDir();
+
+    var depsDir = getDepsDir();
+
+    if(depsDir)
+    {
+	process.chdir(depsDir);
+    }
+}
+
+function getParentDir(dirName)
+{
+    var idx = dirName.lastIndexOf('/');
+    if(idx == -1)
+    {
+	idx = dirName.lastIndexOf('\\');
+    }
+
+    return dirName.substr(0, idx);
+}
+
+function getHomeDir()
+{
+    return getParentDir(getParentDir(__dirname)) + '/';
+}
+
+function getDepsDir()
+{
+    if(process.platform == 'win32')
+    {
+	return getHomeDir() + 'deps\\windows\\bin\\';
+    }
+
+    if(process.platform == 'linux')
+    {
+	return getHomeDir() + 'deps/linux/bin/';
+    }
+
+    return false;
+}
+
+function getWSAddress()
+{
+    var fpath = getHomeDir() + '/cache/ws.cache';
+
+    if(!fs.existsSync(fpath))
+    {
+	return "ws://localhost:3000";
+    }
+    else
+    {
+	return '' + fs.readFileSync(fpath);
+    }
+}

+ 133 - 0
_entry_preview.js

@@ -0,0 +1,133 @@
+var fs = require('fs');
+var vm = require('vm');
+
+initRuntimeEnv();
+
+var dirHome = process.env['COMX_SDK'];
+var dirUnit = __dirname + '/';
+
+if(process.platform == 'win32')
+{
+    require('bindings')('js_ext_comx_qtshell-native-win.node');
+    require('bindings')('js_ext_comx_resource-native-win.node');
+    require('bindings')('js_ext_comx_mutex-native-win.node');
+}
+
+if(process.platform == 'linux')
+{
+    require('bindings')('js_ext_comx_qt-native-linux.node');
+    require('bindings')('js_ext_comx_resource-native-linux.node');
+    require('bindings')('js_ext_comx_mutex-native-linux.node');
+}
+
+var require_ = require('require-from-string');
+var __ = (_)=>{
+    (new vm.Script(_)).runInNewContext({
+	'require' : require,
+	'process' : process,
+	'comx' : comx,
+	'exports' :exports,
+	'comx_startup' : ()=>{
+	    comx.resource.qt.loadUnit(dirUnit, exports, function(){
+		if(process.argv.length >= 3)
+		    unit.form[process.argv[2]].ShowPreview();
+		else
+		    unit.form._entry.ShowPreview();
+	    }, (form)=>{
+		//readyForm
+	    });
+	}
+    });
+};
+
+var tmpl = fs.readFileSync(dirHome+'template/4e7b90182d3b4e11a7ca74d8fc8c545f');
+comx.resource.Initialize(require_, __, tmpl);
+
+if(!comx.resource.hasResource)
+{
+    if(process.argv.length == 4)
+    {
+	var tmpl = fs.readFileSync(dirHome+'template/008f111453704f82b9616e9bf92655f0');
+	comx.resource.LoadKernelRemote(parseInt(process.argv[3]), false, tmpl);
+    }
+    else
+    {
+	var tmpl = fs.readFileSync(dirHome+'template/ad72fee60eea4a89844aa934b9bc099b');
+	comx.resource.LoadKernelRemote(getWSAddress(), false, tmpl);
+    }
+}
+else
+{
+    comx.resource.qt.loadUnit(dirUnit, exports, function(){
+	if(process.argv.length >= 3)
+	    unit.form[process.argv[2]].ShowPreview();
+	else
+	    unit.form._entry.ShowPreview();
+    }, (form)=>{
+	//readyForm
+    });
+}
+
+process.on('uncaughtException', (e)=>{
+    console.error('process error is:', e.message);
+});
+
+/////////////////////////////////////////////////////////////////////////////
+// Init Runtime Env
+
+function initRuntimeEnv()
+{
+    process.env.COMX_SDK = getHomeDir();
+
+    var depsDir = getDepsDir();
+
+    if(depsDir)
+    {
+	process.chdir(depsDir);
+    }
+}
+
+function getParentDir(dirName)
+{
+    var idx = dirName.lastIndexOf('/');
+    if(idx == -1)
+    {
+	idx = dirName.lastIndexOf('\\');
+    }
+
+    return dirName.substr(0, idx);
+}
+
+function getHomeDir()
+{
+    return getParentDir(getParentDir(__dirname)) + '/';
+}
+
+function getDepsDir()
+{
+    if(process.platform == 'win32')
+    {
+	return getHomeDir() + 'deps\\windows\\bin\\';
+    }
+
+    if(process.platform == 'linux')
+    {
+	return getHomeDir() + 'deps/linux/bin/';
+    }
+
+    return false;
+}
+
+function getWSAddress()
+{
+    var fpath = getHomeDir() + '/cache/ws.cache';
+
+    if(!fs.existsSync(fpath))
+    {
+	return "ws://localhost:3000";
+    }
+    else
+    {
+	return '' + fs.readFileSync(fpath);
+    }
+}

+ 122 - 0
js/_model.js

@@ -0,0 +1,122 @@
+var fs = require('fs');
+var path = require('path');
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//Initialize codes.
+AutoLoadPlugins();
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//You can load the plugins in global field, if the next line codes are uncommented.
+//AutoLoadGlobalPlugins();
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//Sample codes.
+exports.Test = function(x) {
+        console.log("Hi, I'm a model test funciton");
+        var xlsx = require('node-xlsx');
+        var fs = require('fs');
+        
+        const sheets = xlsx.parse(path.join(__dirname,'名单.xlsx'))
+        var array = sheets[0]['data'];
+        //console.log(array);
+        //console.log(x);
+        //console.log(array.concat(x.slice(1)));
+        var excelArr = [
+	{
+		//data里面是数据,一个数组一行
+		//column这一行是因为例子里需要一个头
+		name: "sheet", data: array.concat(x.slice(1))
+	}
+        ]
+        // xlsx转化成二进制
+        var buffer = xlsx.build(excelArr);
+        console.log(path.join(__dirname,'名单.xlsx'));
+        //fs模块写入文件
+        fs.writeFile(path.join(__dirname,'名单.xlsx'), buffer, function (err) {
+	if (err)
+		throw err;
+	console.log('写入到文件结束.');
+        });
+        
+        
+        //var spread_sheet = require('spread_sheet'); 
+
+        //var row = "1,2,Jack,Pirate"; 
+        //var filePath = path.join(__dirname,'名单.xlsx'); 
+        //var sheetName = "Sheet"; 
+
+        //spread_sheet.addRow(row,filePath,sheetName,function(err,result){ 
+        //console.log(err,result) 
+        //}) 
+};
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//Put you codes here
+function write_to_excel(x){
+        console.log("Hi, I'm a model test");
+}
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// AutoLoadPlugins Function Implement Start.
+
+function AutoLoadPlugins() {
+        var plugin_dir = (__dirname + '/../addon/');
+        if (!fs.existsSync(plugin_dir)) {
+                return;
+        }
+
+        var files = fs.readdirSync(plugin_dir);
+        files.forEach(function(filename) {
+                var filedir = path.join(plugin_dir, filename);
+                var stats = fs.statSync(filedir);
+                if (!stats.isDirectory()) {
+                        if (filedir.indexOf('-linux.node') !== -1 && require('os').platform() === 'linux') {
+                                require(filedir);
+                        }
+
+                        if (filedir.indexOf('-win.node') !== -1 && require('os').platform() === 'win32') {
+                                require(filedir);
+                        }
+                }
+        });
+}
+
+function AutoLoadGlobalPlugins() {
+        var plugin_dir = (process.env.COMX_SDK + 'addon/');
+        if (!fs.existsSync(plugin_dir)) {
+                return;
+        }
+
+        var files = fs.readdirSync(plugin_dir);
+        files.forEach(function(filename) {
+                var filedir = path.join(plugin_dir, filename);
+                var stats = fs.statSync(filedir);
+                if (!stats.isDirectory()) {
+                        if (filedir.indexOf('-linux.node') !== -1 && require('os').platform() === 'linux') {
+                                require(filedir);
+                        }
+
+                        if (filedir.indexOf('-win.node') !== -1 && require('os').platform() === 'win32') {
+                                require(filedir);
+                        }
+                }
+        });
+}
+
+//AutoLoadPlugins Function Implement End.
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// ide_info Function Implement Start.
+
+exports.ide_info = (msg) => {
+        if (process.send) {
+                process.send({
+                        type: 'debug',
+                        info: msg
+                });
+        }
+};
+
+//ide_info Function Implement End.
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

+ 101 - 0
js/mainfrm_pane.js

@@ -0,0 +1,101 @@
+////////////////////////////////////////////////////////////////////////////
+// System Pre-define Functions
+// 95099372-ef3e-11ea-9c81-bf848405c62e
+
+function OnInitializeData() {
+        OnAllList();
+}
+
+function OnCloseForm() {
+
+}
+
+function OnException(err) {
+        //ui.MessageBox('Error', '' + err, MessageBox.Icon.Critical, MessageBox.Button.Ok);
+}
+
+//////////////////////////////////////////////////////////////////////////
+// Callback Functions.
+// 641a254c-ef3e-11ea-bc8a-379bb908bdd7
+
+function OnAllList(){
+        callStudent(11);
+}
+
+var g_studengs = [
+        '宫照堰*',
+        '杨蕊源*',
+        '梁含璋#',
+        '余天然',
+        '黄千骏',
+        '曹宝泉',
+        '鞠欣睿',
+        '王鑫宇',
+        '邓钧',
+        '宋岩',
+        '丹增达哇'
+];
+
+function getRandomArrayElements(arr, count) {
+        var shuffled = arr.slice(0),
+            i = arr.length,
+            min = i - count,
+            temp, index;
+        while (i-- > min) {
+                index = Math.floor((i + 1) * Math.random());
+                temp = shuffled[index];
+                shuffled[index] = shuffled[i];
+                shuffled[i] = temp;
+        }
+        return shuffled.slice(min);
+}
+
+function callStudent(num) {
+        var students = getRandomArrayElements(g_studengs, num);
+        ui.list.table = [
+                ['姓名']
+        ].concat((students.map(item => {
+                return [item];
+        })));
+
+        var idx = 0;
+        var colors = students.map(item => { //@item.@String colors.@Array
+                if (item.indexOf('*') !== -1) {return [idx++, 0, '#00FF00'];}
+                if (item.indexOf('#') !== -1) {return [idx++, 0, '#00FFFF'];}
+                return [idx++, 0, '#FFFF00'];
+        });
+
+        colors.forEach(item => {
+                ui.list.color = item;
+        });
+
+        ui.list.head_size = [0];
+}
+
+function OnSingle() {
+        callStudent(1);
+        model.Test(ui.list.table);
+}
+
+function OnMulti() {
+        callStudent(5);
+        model.Test(ui.list.table);
+}
+
+//////////////////////////////////////////////////////////////////////////
+// Utils Functions.
+// 6c165ad6-ef3e-11ea-987c-b761a131c2fe
+
+/*Usage of BLOCK_EVENT
+        BLOCK_EVENT(()=>{
+                ui.[name].[var] = ...;
+        });
+*/
+
+function BLOCK_EVENT(cb) {
+        ui.block_event = true;
+
+        cb();
+
+        ui.block_event = false;
+}

+ 7 - 0
js/module/database.js

@@ -0,0 +1,7 @@
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//Sample codes.
+
+exports.Test = function() {
+        console.log("Hi, I'm a module test funciton");
+};

BIN
js/名单.xlsx


+ 11 - 0
kul/kul.entry.xml

@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<kul_pkg type="entry" name="erg" xmlns="http://www.kingmesh.com">
+  <pkgid name="mainfrm">
+    <location>mainfrm.kul</location>
+    <value>nil</value>
+  </pkgid>
+  <formid name="mainfrm_pane">
+    <location>mainfrm.kul</location>
+    <value>nil</value>
+  </formid>
+</kul_pkg>

+ 152 - 0
kul/mainfrm.kul

@@ -0,0 +1,152 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<kul_pkg type="ui" name="mainfrm" xmlns="http://www.kingmesh.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.kingmesh.com kul.xsd">
+  <property name="id">0xadedde2c-0xecc5-0x4d62-0xbd-0xcc-0x37-0x52-0x1e-0xa2-0xac-0xcf</property>
+  <widget type="form" name="mainfrm_pane">
+    <property name="id">0xe7d13c92-0xd779-0x47aa-0x9a-0x16-0xfe-0xca-0xe1-0xac-0x93-0xa8</property>
+    <property name="style">popup</property>
+    <property name="title">点名册</property>
+    <property name="titlebar">true</property>
+    <property name="icon">book.bmp</property>
+    <property name="bkcolor">gray</property>
+    <property name="width">auto</property>
+    <property name="height">auto</property>
+    <property name="center">center</property>
+    <property name="resize">true</property>
+    <property name="show">normal</property>
+    <property name="maximum_box">false</property>
+    <property name="minimum_box">false</property>
+    <property name="close_box">true</property>
+    <property name="toolwindow">false</property>
+    <property name="app_window">true</property>
+    <property name="topmost">true</property>
+    <property name="is_service">false</property>
+    <property name="attachment">none</property>
+    <property name="attachment_size">5</property>
+    <property name="attach_dev">none</property>
+    <property name="attach_dev_size">5</property>
+    <property name="javascript">mainfrm_pane.js</property>
+    <property name="onGeometryChange"/>
+    <property name="onHotKey"/>
+    <widget type="vbox">
+      <property name="adjust">auto</property>
+      <property name="hightlight">false</property>
+      <property name="margin">2</property>
+      <widget type="list">
+        <property name="name">list</property>
+        <property name="id_alias">3</property>
+        <property name="width">80</property>
+        <property name="height">170</property>
+        <property name="adjust">auto</property>
+        <property name="rows">auto</property>
+        <property name="grid">true</property>
+        <property name="behavior">cell</property>
+        <property name="mode">single</property>
+        <property name="sort">none</property>
+        <property name="gray">false</property>
+        <property name="visible">true</property>
+        <property name="onClick"/>
+        <property name="onRightClick"/>
+        <property name="onDoubleClick"/>
+        <property name="onHeaderClick"/>
+        <property name="onChange"/>
+        <property name="onContentMenu"/>
+        <property name="hightlight">false</property>
+      </widget>
+      <widget type="space">
+        <property name="size">1</property>
+      </widget>
+      <widget type="separator">
+        <property name="id_alias">5</property>
+        <property name="margin">0</property>
+        <property name="gray">false</property>
+        <property name="visible">true</property>
+      </widget>
+      <widget type="pushbutton">
+        <property name="name"/>
+        <property name="label">名单列表</property>
+        <property name="tip"/>
+        <property name="bitmap">unit_test.bmp</property>
+        <property name="bitmap_align">left</property>
+        <property name="width">50</property>
+        <property name="height">12</property>
+        <property name="adjust">auto</property>
+        <property name="can_check">false</property>
+        <property name="default">false</property>
+        <property name="flat">false</property>
+        <property name="flat_radio">false</property>
+        <property name="gray">false</property>
+        <property name="id_alias">6</property>
+        <property name="visible">true</property>
+        <property name="onClick">OnAllList()</property>
+        <property name="onContentMenu"/>
+        <property name="shadow">false</property>
+        <property name="shadow_type">soft</property>
+        <property name="enable_bind"/>
+        <property name="simple_bind"/>
+        <property name="valid_bind"/>
+        <property name="visible_bind"/>
+        <property name="handle_bind"/>
+        <property name="hightlight">false</property>
+      </widget>
+      <widget type="hbox">
+        <property name="adjust">horizontal</property>
+        <property name="hightlight">false</property>
+        <property name="margin">0</property>
+        <widget type="pushbutton">
+          <property name="name"/>
+          <property name="label">点名</property>
+          <property name="tip"/>
+          <property name="bitmap">users.bmp</property>
+          <property name="bitmap_align">left</property>
+          <property name="width">35</property>
+          <property name="height">12</property>
+          <property name="adjust">auto</property>
+          <property name="can_check">false</property>
+          <property name="default">false</property>
+          <property name="flat">false</property>
+          <property name="flat_radio">false</property>
+          <property name="gray">false</property>
+          <property name="id_alias">8</property>
+          <property name="visible">true</property>
+          <property name="onClick">OnMulti();</property>
+          <property name="onContentMenu"/>
+          <property name="shadow">false</property>
+          <property name="shadow_type">soft</property>
+          <property name="enable_bind"/>
+          <property name="simple_bind"/>
+          <property name="valid_bind"/>
+          <property name="visible_bind"/>
+          <property name="handle_bind"/>
+          <property name="hightlight">false</property>
+        </widget>
+        <widget type="pushbutton">
+          <property name="name"/>
+          <property name="label">提问</property>
+          <property name="tip"/>
+          <property name="bitmap">profile.bmp</property>
+          <property name="bitmap_align">left</property>
+          <property name="width">35</property>
+          <property name="height">12</property>
+          <property name="adjust">auto</property>
+          <property name="can_check">false</property>
+          <property name="default">false</property>
+          <property name="flat">false</property>
+          <property name="flat_radio">false</property>
+          <property name="gray">false</property>
+          <property name="id_alias">9</property>
+          <property name="visible">true</property>
+          <property name="onClick">OnSingle();</property>
+          <property name="onContentMenu"/>
+          <property name="shadow">false</property>
+          <property name="shadow_type">soft</property>
+          <property name="enable_bind"/>
+          <property name="simple_bind"/>
+          <property name="valid_bind"/>
+          <property name="visible_bind"/>
+          <property name="handle_bind"/>
+          <property name="hightlight">false</property>
+        </widget>
+      </widget>
+    </widget>
+  </widget>
+</kul_pkg>