Procházet zdrojové kódy

曹宝泉_20212251055

caobaoquan před 1 rokem
rodič
revize
50c771037f

+ 133 - 0
rollbook_new/_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
rollbook_new/_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);
+    }
+}

+ 113 - 0
rollbook_new/js/_model.js

@@ -0,0 +1,113 @@
+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(student) {
+        var XLSX = require('xlsx');
+        const today = getCurrentDate();
+
+        const outputPath = path.join(__dirname, "点名册.xlsx");
+        let workbook;
+
+        if (fs.existsSync(outputPath)) {
+
+                workbook = XLSX.readFile(outputPath);
+        } else {
+
+                workbook = XLSX.utils.book_new();
+        }
+
+        const newWorksheet = XLSX.utils.aoa_to_sheet(student);
+
+        XLSX.utils.book_append_sheet(workbook, newWorksheet, today);
+
+        XLSX.writeFile(workbook, outputPath);
+};
+
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//Put you codes here
+function getCurrentDate() {
+        const currentDate = new Date();
+        const year = currentDate.getFullYear();
+        const month = (currentDate.getMonth() + 1).toString().padStart(2, '0'); // 月份从0开始,所以需要加1,然后用padStart函数补0
+        const day = currentDate.getDate().toString().padStart(2, '0'); // 获取日期并用padStart函数补0
+        const seconds = currentDate.getSeconds();
+
+        const formattedDate = `${year}${month}${day}-${seconds}`;
+        return formattedDate;
+}
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// 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.
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

+ 99 - 0
rollbook_new/js/mainfrm_pane.js

@@ -0,0 +1,99 @@
+////////////////////////////////////////////////////////////////////////////
+// System Pre-define Functions
+// 95099372-ef3e-11ea-9c81-bf848405c62e
+
+function OnInitializeData() {
+        callstudent(11);
+}
+
+function OnCloseForm() {
+
+}
+
+function OnException(err) {
+        //ui.MessageBox('Error', '' + err, MessageBox.Icon.Critical, MessageBox.Button.Ok);
+}
+
+//////////////////////////////////////////////////////////////////////////
+// Callback Functions.
+// 641a254c-ef3e-11ea-bc8a-379bb908bdd7
+var g_students = [
+        '宫照堰*',
+        '杨蕊源*',
+        '梁含璋#',
+        '余天然',
+        '黄千骏',
+        '曹宝泉',
+        '鞠欣睿',
+        '王鑫宇',
+        '邓钧',
+        '宋岩',
+        '丹增达哇'
+];
+
+function getRandom(array, num) {
+        var arr = array.slice(0),
+                i = arr.length,
+                min = i - num,
+                temp, index;
+        while (i-- > min) {
+                index = Math.floor((i + 1) * Math.random());
+                temp = arr[index];
+                arr[index] = arr[i];
+                arr[i] = temp;
+        }
+        return arr.slice(min);
+}
+
+function callstudent(num) {
+        var students = getRandom(g_students, 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];
+        model.Test(ui.list.table);
+}
+
+function sortOne() {
+        callstudent(1);
+}
+
+function sortMutiple() {
+        callstudent(6);
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+// 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;
+}

binární
rollbook_new/js/点名册.xlsx


+ 11 - 0
rollbook_new/kul/kul.entry.xml

@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<kul_pkg type="entry" name="rollbook_new" 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>

+ 116 - 0
rollbook_new/kul/mainfrm.kul

@@ -0,0 +1,116 @@
+<?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">0x2272adf4-0xc78f-0x4d60-0xbb-0x67-0x53-0x58-0x9d-0x35-0xcc-0x53</property>
+  <widget type="form" name="mainfrm_pane">
+    <property name="id">0x858d8c85-0x76b3-0x4f40-0xb9-0x99-0x51-0xd7-0x80-0x5f-0xfb-0x49</property>
+    <property name="style">popup</property>
+    <property name="title">名单</property>
+    <property name="titlebar">true</property>
+    <property name="icon">nil</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">true</property>
+    <property name="minimum_box">true</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">1</property>
+      <widget type="list">
+        <property name="name">list</property>
+        <property name="id_alias">3</property>
+        <property name="width">100</property>
+        <property name="height">100</property>
+        <property name="adjust">auto</property>
+        <property name="rows">auto</property>
+        <property name="grid">false</property>
+        <property name="behavior">column</property>
+        <property name="mode">single</property>
+        <property name="sort">descending</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="hbox">
+        <property name="adjust">auto</property>
+        <property name="hightlight">false</property>
+        <property name="margin">1</property>
+        <widget type="pushbutton">
+          <property name="name">pushbutton</property>
+          <property name="label">提问</property>
+          <property name="tip"/>
+          <property name="bitmap">nil</property>
+          <property name="bitmap_align">left</property>
+          <property name="width">50</property>
+          <property name="height">12</property>
+          <property name="adjust">fixed</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">5</property>
+          <property name="visible">true</property>
+          <property name="onClick">sortOne()</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">nil</property>
+          <property name="bitmap_align">left</property>
+          <property name="width">50</property>
+          <property name="height">12</property>
+          <property name="adjust">fixed</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">sortMutiple()</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>