index.html 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8"/>
  5. <link rel="icon" type="image/svg+xml" href="/vite.svg"/>
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  7. <title>cocos fsm</title>
  8. </head>
  9. <body>
  10. <div id="app"></div>
  11. <script type="module" src="/src/main.js"></script>
  12. <style>
  13. textarea {
  14. background-color: rgb(255, 255, 224);
  15. resize: none;
  16. border-color: yellow;
  17. border-style: solid dashed;
  18. border-width: 10px;
  19. border-radius: 15px 15px;
  20. }
  21. .fsm-menu-item:hover {
  22. border-style: none;
  23. }
  24. .fsm-menu-item {
  25. color: black;
  26. }
  27. .fsm-menu-item:hover {
  28. text-decoration: none;
  29. color: lightgray;
  30. }
  31. .fsm-menu {
  32. padding-left: 5px;
  33. padding-right: 5px;
  34. height: 25px;
  35. }
  36. </style>
  37. <link href="/src/jsoneditor.css" rel="stylesheet" type="text/css">
  38. <script src="/src/jsoneditor.js"></script>
  39. <script src="/src/notie.js"></script>
  40. <script src="/src/go.js"></script>
  41. <link href="/src/notie.css" rel="stylesheet" type="text/css">
  42. <div id="menu" style="z-index:2;left:0px;right:0px;top:0px;height:20px;background-color:white;position: absolute">
  43. <span class="fsm-menu"><a href="#" class="fsm-menu-item" onclick="importWorkFlow();">导入(alt + o)</a></span>
  44. <span class="fsm-menu"><a href="#" class="fsm-menu-item" onclick="exportWorkFlow()">导出(alt + e)</a></span>
  45. <span class="fsm-menu"><a href="#" class="fsm-menu-item" onclick="saveWorkFlow();">保存(alt + s)</a></span>
  46. <span class="fsm-menu"><a href="#" class="fsm-menu-item"
  47. onclick="switchModeWorkFlow();">切换模式(alt + q)</a></span>
  48. <span class="fsm-menu"><a href="#" class="fsm-menu-item"
  49. onclick="setInitStateWorkFlow();">初始状态(alt + c)</a></span>
  50. <span class="fsm-menu"><a href="#" class="fsm-menu-item" onclick="resetWorkFlow();">重置清空(alt + r)</a></span>
  51. <span class="fsm-menu"><a href="#" class="fsm-menu-item" onclick="getHelp();">帮助(alt + h)</a></span>
  52. <span class="fsm-menu"><a href="#" class="fsm-menu-item" onclick="getAbout();">关于</a></span>
  53. </div>
  54. <h3 id="tips" style="color:#B0B0B0; z-index:3;position:absolute; left:25px;bottom:0px;">norm mode</h3>
  55. <h3 id="tips2" style="color:#B0B0B0; z-index:3;position:absolute; left:25px;bottom:25px;">help : alt+h </h3>
  56. <h3 id="reEditNameTips" style="color:#B0B0B0; z-index:3;position:absolute; left:25px;bottom:50px;"></h3>
  57. <div id="myDiagramDiv"
  58. style="z-index:1;border:1px #ccc solid;position:absolute; top:20px; left:0px; right:405px; bottom:0px;background-color: #444;"></div>
  59. <div id="jsonEditorDiv"
  60. style="border:1px #ccc solid;width:400px;background-color: #444;position:absolute; right:0px; bottom:0px;top: 20px;"></div>
  61. <script>
  62. /// 测试Ipc监听
  63. // require('electron').ipcRenderer.on('test-render-on', function(event, args) {
  64. // alert("hello");
  65. // document.getElementById("tips").innerHTML = args;
  66. // });
  67. //流程加锁
  68. let saving = false;
  69. //保存完成
  70. // require("electron").ipcRenderer.on("saved", function (event, args) {
  71. // saving = false;
  72. // })
  73. //关于
  74. let getAbout = function () {
  75. let info =
  76. `
  77. 作者:qbkivlin
  78. 寄语:望 cocos creator 越来越好
  79. `;
  80. alert(info);
  81. }
  82. window.addEventListener('message', (event) => {
  83. // 处理接收到的消息
  84. console.log('iframe Message received:', event.data);
  85. let result = event.data.data
  86. if (event.data.message == 're-edit-fsm') {
  87. let fileName = result.name;
  88. let flowForGoJs = JSON.parse(result.model);
  89. globalCallbacksText = flowForGoJs.globalCallbacksText;
  90. editor.setText(globalCallbacksText);
  91. expandJson();
  92. if (flowForGoJs) {
  93. myDiagram.model = go.Model.fromJson(flowForGoJs);
  94. document.getElementById("reEditNameTips").innerText = fileName;
  95. // fix bug: should set oldInitialStateKey when reload the model
  96. oldInitialStateKey = getInitialKeyFromGoJs(flowForGoJs);
  97. } else {
  98. notie.removeAll();
  99. notie.alert({type: "error", text: "状态机解析出错", stay: true});
  100. }
  101. } else if (event.data.message == 'import-failed') {
  102. notie.removeAll();
  103. notie.alert({type: "error", text: "状态机导入出错", stay: true});
  104. } else if (event.data.message == 'save-callback') {
  105. saving = false;
  106. if (result?.error) {
  107. notie.removeAll();
  108. notie.alert({
  109. type: "error",
  110. text: "不存在状态机保存源,请通过导出的方式( alt + e )生成状态机代码",
  111. stay: true
  112. });
  113. }
  114. } else if (event.data.message == 'export-callback') {
  115. if (result.isFileExists) {
  116. notie.removeAll();
  117. notie.alert({type: "error", text: "文件名存在冲突", stay: true});
  118. } else {
  119. //修改: 直接让main进程进行代码保存
  120. safetySaveBeforeExport();
  121. let modelAsText = myDiagram.model.toJson();
  122. let modelAsObj = JSON.parse(modelAsText);
  123. modelAsObj.globalCallbacksText = globalCallbacksText;
  124. saving = true;
  125. //todo 添加异步验证
  126. let postDataTmp = {
  127. message: "save",
  128. args: {isExport: true, model: modelAsObj, className: result.className},
  129. }
  130. window.parent.postMessage(postDataTmp, '*');
  131. }
  132. }
  133. });
  134. //导入
  135. let importWorkFlow = function () {
  136. let postData = {
  137. message: "import",
  138. }
  139. window.parent.postMessage(postData, '*');
  140. //Editor.Message.send("visual-fsm:import");
  141. }
  142. document.addEventListener("keydown", function (e) {
  143. if ((e.key.toLowerCase() == 'o' || e.code == "KeyO") && e.altKey) {
  144. importWorkFlow();
  145. }
  146. });
  147. //清空
  148. let resetWorkFlow = function () {
  149. notie.removeAll();
  150. notie.confirm({
  151. text: "确定要清空当前状态机编辑面板吗?",
  152. submitText: "确定", // optional, default = 'Yes'
  153. cancelText: "取消", // optional, default = 'Cancel'
  154. position: "top", // optional, default = 'top', enum: ['top', 'bottom']
  155. submitCallback: function () {
  156. let modelAsObj = myDiagram.model;
  157. modelAsObj.nodeDataArray = [];
  158. modelAsObj.linkDataArray = [];
  159. myDiagram.model = modelAsObj;
  160. editor.setText(rawGlobalCallbacksText);
  161. expandJson();
  162. document.getElementById("reEditNameTips").innerText = "";
  163. let postData = {
  164. message: "reset",
  165. }
  166. window.parent.postMessage(postData, '*');
  167. }, // optional
  168. cancelCallback: function () {
  169. }, // optional
  170. });
  171. }
  172. document.addEventListener("keydown", function (e) {
  173. if ((e.key.toLowerCase() == 'r' || e.code == "KeyR") && e.altKey) {
  174. resetWorkFlow();
  175. }
  176. });
  177. let globalCallbacksText = `{"enter":[],"leave":[],"before":[],"after":[]}`;
  178. //初始状态的全局回调
  179. let rawGlobalCallbacksText = `{"enter":[],"leave":[],"before":[],"after":[]}`;
  180. let modesArray = ['code', 'form', 'text', 'tree', 'view'];
  181. let expandableArray = ['tree', 'view', 'form'];
  182. var container = document.getElementById("jsonEditorDiv");
  183. var options = {
  184. sortObjectKeys: false,
  185. mode: 'tree',
  186. modes: modesArray, // allowed modes
  187. onError: function (err) {
  188. notie.removeAll();
  189. notie.alert({type: "error", text: err, stay: true});
  190. },
  191. onModeChange: function () {
  192. expandJson();
  193. },
  194. onEditable: function (node) {
  195. if (node.field === "enter" || node.field === "leave" || node.field === "before" || node.field === "after")
  196. return {field: false, value: true};
  197. return true;
  198. }
  199. };
  200. var editor = new JSONEditor(container, options);
  201. editor.setText(globalCallbacksText);
  202. let expandJson = function () {
  203. let currentMode = editor.getMode();
  204. if (expandableArray.some((value) => {
  205. return value === currentMode
  206. }))
  207. editor.expandAll();
  208. }
  209. expandJson();
  210. var $ = go.GraphObject.make; // for conciseness in defining templates
  211. var myDiagram =
  212. $(go.Diagram, "myDiagramDiv", // must name or refer to the DIV HTML element
  213. {
  214. // start everything in the middle of the viewport
  215. initialContentAlignment: go.Spot.Center,
  216. // have mouse wheel events zoom in and out instead of scroll up and down
  217. "toolManager.mouseWheelBehavior": go.ToolManager.WheelZoom,
  218. // support double-click in background creating a new node
  219. "clickCreatingTool.archetypeNodeData": {text: "state", isInit: false},
  220. // enable undo & redo
  221. "undoManager.isEnabled": true,
  222. //"toolManager.linkingTool.isEnabled":false,
  223. });
  224. myDiagram.toolManager.linkingTool.isEnabled = false;
  225. myDiagram.scrollMode = go.Diagram.InfiniteScroll;
  226. let switchModeWorkFlow = function () {
  227. myDiagram.toolManager.linkingTool.isEnabled = !myDiagram.toolManager.linkingTool.isEnabled;
  228. document.getElementById("tips").innerHTML = myDiagram.toolManager.linkingTool.isEnabled ? "link mode" : "norm mode";
  229. }
  230. document.addEventListener("keydown", function (e) {
  231. if ((e.key.toLowerCase() == 'q' || e.code == "KeyQ") && e.altKey) {
  232. switchModeWorkFlow();
  233. }
  234. }.bind(this));
  235. let preValidateInitialState = function () {
  236. let flowForGoJs = myDiagram.model;
  237. let nodeDataArray = flowForGoJs.nodeDataArray;
  238. for (let i = 0, l = nodeDataArray.length; i < l; i++) {
  239. if (nodeDataArray[i].isInit) {
  240. return true;
  241. }
  242. }
  243. return false;
  244. }
  245. let isEmptyStateCheck = function () {
  246. let modelAsObj = myDiagram.model;
  247. return !modelAsObj.nodeDataArray.length;
  248. }
  249. let saveWorkFlow = function () {
  250. //exportSelect();
  251. //验证初始化状态
  252. if (saving) {
  253. return;
  254. }
  255. let isEmptyState = isEmptyStateCheck();
  256. if (isEmptyState) {
  257. notie.removeAll();
  258. notie.alert({type: "error", text: "状态机不能为空", stay: true});
  259. return;
  260. }
  261. let isPass = preValidateInitialState();
  262. if (!isPass) {
  263. notie.removeAll();
  264. notie.alert({type: "error", text: "未指定状态机初始状态", stay: true});
  265. return;
  266. }
  267. let fsmName = document.getElementById("reEditNameTips").innerText;
  268. notie.removeAll();
  269. notie.confirm({
  270. text: `确定要保存状态机 ${fsmName} 吗?`,
  271. submitText: "确定", // optional, default = 'Yes'
  272. cancelText: "取消", // optional, default = 'Cancel'
  273. position: "top", // optional, default = 'top', enum: ['top', 'bottom']
  274. submitCallback: function () {
  275. //修改: 直接让main进程进行代码保存
  276. safetySaveBeforeExport();
  277. let modelAsText = myDiagram.model.toJson();
  278. let modelAsObj = JSON.parse(modelAsText);
  279. modelAsObj.globalCallbacksText = globalCallbacksText;
  280. saving = true;
  281. //todo 添加异步验证 done
  282. let postData = {
  283. message: "save",
  284. args: {isExport: false, model: modelAsObj},
  285. }
  286. window.parent.postMessage(postData, '*');
  287. }, // optional
  288. cancelCallback: function () {
  289. }, // optional
  290. });
  291. }
  292. document.addEventListener("keydown", function (e) {
  293. if ((e.key.toLowerCase() == 's' || e.code == "KeyS") && e.altKey) {
  294. saveWorkFlow();
  295. }
  296. });
  297. let exportWorkFlow = function () {
  298. //exportSelect();
  299. //验证初始化状态
  300. if (saving) {
  301. return;
  302. }
  303. let isEmptyState = isEmptyStateCheck();
  304. if (isEmptyState) {
  305. notie.removeAll();
  306. notie.alert({type: "error", text: "状态机不能为空", stay: true});
  307. return;
  308. }
  309. let isPass = preValidateInitialState();
  310. if (!isPass) {
  311. notie.removeAll();
  312. notie.alert({type: "error", text: "未指定状态机初始状态", stay: true});
  313. return;
  314. }
  315. classNameInput(function (value) {
  316. let className = value;
  317. //todo 添加同名验证
  318. if (className) {
  319. let postData = {
  320. message: "checkSameName",
  321. args: {className: className},
  322. }
  323. window.parent.postMessage(postData, '*')
  324. }
  325. });
  326. }
  327. document.addEventListener("keydown", function (e) {
  328. if ((e.key.toLowerCase() == 'e' || e.code == "KeyE") && e.altKey) {
  329. exportWorkFlow();
  330. }
  331. })
  332. document.addEventListener("keydown", function (e) {
  333. if ((e.key.toLowerCase() == 'h' || e.code == "KeyH") && e.altKey) {
  334. getHelp();
  335. }
  336. });
  337. let setInitStateWorkFlow = function () {
  338. if (editKey !== null) {
  339. let node = myDiagram.findNodeForKey(editKey);
  340. if (node) {
  341. myDiagram.model.startTransaction("change isInit");
  342. myDiagram.model.setDataProperty(node.data, "isInit", !node.data.isInit);
  343. myDiagram.model.commitTransaction("change isInit");
  344. }
  345. }
  346. if (oldInitialStateKey !== null && oldInitialStateKey !== editKey) {
  347. let node = myDiagram.findNodeForKey(oldInitialStateKey);
  348. if (node) {
  349. myDiagram.model.startTransaction("change isInit");
  350. myDiagram.model.setDataProperty(node.data, "isInit", false);
  351. myDiagram.model.commitTransaction("change isInit");
  352. }
  353. }
  354. oldInitialStateKey = editKey;
  355. }
  356. document.addEventListener("keydown", function (e) {
  357. if ((e.key.toLowerCase() == 'c' || e.code == "KeyC") && e.altKey) {
  358. setInitStateWorkFlow();
  359. }
  360. })
  361. var editKey = null;
  362. var selectLink = false;
  363. var linkData = null;
  364. var multiSelect = false;
  365. var oldInitialStateKey = null;
  366. myDiagram.addDiagramListener("ChangedSelection", function (e) {
  367. if (editKey) {
  368. let node = myDiagram.findNodeForKey(editKey);
  369. if (node) {
  370. myDiagram.model.startTransaction("change callbacks");
  371. myDiagram.model.setDataProperty(node.data, "callbacks", editor.getText());
  372. myDiagram.model.commitTransaction("change callbacks");
  373. }
  374. }
  375. if (selectLink) {
  376. let link = myDiagram.findLinkForData(linkData);
  377. if (link) {
  378. myDiagram.model.startTransaction("change callbacks");
  379. myDiagram.model.setDataProperty(link.data, "callbacks", editor.getText());
  380. myDiagram.model.commitTransaction("change callbacks");
  381. }
  382. }
  383. if (!editKey && !selectLink && !multiSelect) {
  384. globalCallbacksText = editor.getText();
  385. }
  386. let selection = e.diagram.selection;
  387. let count = selection.count;
  388. if (count === 1) {
  389. let obj = selection.first();
  390. editKey = obj.data.key;
  391. if (editKey) {
  392. //document.getElementById("txt").value = "";
  393. //Editor.log(obj.data.parameter);
  394. //editor.set(JSON.parse(obj.data.paramter));
  395. selectLink = false;
  396. multiSelect = false;
  397. editor.setText(obj.data.callbacks || '{"enter":[],"leave":[]}');
  398. expandJson();
  399. } else {
  400. // this is link
  401. selectLink = true;
  402. multiSelect = false;
  403. editor.setText(obj.data.callbacks || '{"before":[],"after":[]}');
  404. linkData = obj.data;
  405. expandJson();
  406. }
  407. } else if (count === 0) {
  408. editKey = null;
  409. selectLink = false;
  410. multiSelect = false;
  411. editor.setText(globalCallbacksText);
  412. expandJson();
  413. } else if (count >= 2) {
  414. multiSelect = true;
  415. }
  416. //editor.expandAll();
  417. });
  418. // define the Node template
  419. myDiagram.nodeTemplate =
  420. $(go.Node, "Auto",
  421. new go.Binding("location", "loc", go.Point.parse).makeTwoWay(go.Point.stringify),
  422. // define the node's outer shape, which will surround the TextBlock
  423. $(go.Shape, "RoundedRectangle",
  424. {
  425. parameter1: 20, // the corner has a large radius
  426. //fill: $(go.Brush, "Linear", { 0: "rgb(254, 201, 0)", 1: "rgb(254, 162, 0)" }),
  427. stroke: null,
  428. // portId: "", // this Shape is the Node's port, not the whole Node
  429. // fromLinkable: true, fromLinkableSelfNode: true, fromLinkableDuplicates: true,
  430. // toLinkable: true, toLinkableSelfNode: true, toLinkableDuplicates: true,
  431. // cursor: "pointer"
  432. }, new go.Binding("fill", "isInit", function (s) {
  433. return s ?
  434. $(go.Brush, "Radial", {
  435. 0: "rgb(151,255,151)",
  436. 0.8: "rgb(151,255,151)",
  437. 1: "rgba(151,255,151, 0)"
  438. }) :
  439. $(go.Brush, "Radial", {
  440. 0: "rgb(255,255,224)",
  441. 0.8: "rgb(255,255,224)",
  442. 1: "rgba(255,255,224, 0)"
  443. })
  444. })//.makeTwoWay()
  445. ),
  446. $(go.TextBlock,
  447. {
  448. font: "bold 20pt helvetica, bold arial, sans-serif",
  449. editable: true // editing the text automatically updates the model data
  450. },
  451. new go.Binding("text").makeTwoWay()),
  452. {
  453. portId: "", // this Shape is the Node's port, not the whole Node
  454. fromLinkable: true, fromLinkableSelfNode: true, fromLinkableDuplicates: true,
  455. toLinkable: true, toLinkableSelfNode: true, toLinkableDuplicates: true,
  456. cursor: "pointer"
  457. }
  458. );
  459. myDiagram.linkTemplate =
  460. $(go.Link, // the whole link panel
  461. {
  462. curve: go.Link.Bezier, adjusting: go.Link.Stretch,
  463. reshapable: true, relinkableFrom: true, relinkableTo: true,
  464. toShortLength: 3,
  465. },
  466. new go.Binding("points").makeTwoWay(),
  467. new go.Binding("curviness"),
  468. $(go.Shape, // the link shape
  469. {fill: 'white', stroke: 'white', strokeWidth: 1.5}),
  470. $(go.Shape, // the arrowhead
  471. {toArrow: "standard", fill: 'white', stroke: 'white', strokeWidth: 2}),
  472. $(go.Panel, "Auto",
  473. $(go.Shape, // the label background, which becomes transparent around the edges
  474. {
  475. fill: $(go.Brush, "Radial",
  476. {0: "rgb(240, 240, 240)", 0.3: "rgb(240, 240, 240)", 1: "rgba(240, 240, 240, 0)"}),
  477. stroke: null
  478. }),
  479. $(go.TextBlock, "event",// the label text
  480. {
  481. textAlign: "center",
  482. font: "20pt helvetica, arial, sans-serif",
  483. margin: 10,
  484. editable: true, // enable in-place editing
  485. },
  486. // editing the text automatically updates the model data
  487. new go.Binding("text").makeTwoWay())
  488. )
  489. );
  490. function classNameInput(flowCallback) {
  491. notie.removeAll();
  492. notie.input({
  493. text: "输入状态机文件名?",
  494. submitText: "确认", // optional, default = 'Submit'
  495. cancelText: "取消", // optional, default = 'Cancel'
  496. position: "top", // optional, default = 'top', enum: ['top', 'bottom']
  497. submitCallback: function (value) {
  498. flowCallback(value)
  499. }, // optional
  500. cancelCallback: function () {
  501. }, // optional
  502. autofocus: 'true', // default: 'true'
  503. placeholder: 'FsmImplClass', // default: ''
  504. type: 'text', // default: 'text'
  505. })
  506. }
  507. function safetySaveBeforeExport() {
  508. if (editKey) {
  509. let node = myDiagram.findNodeForKey(editKey);
  510. if (node) {
  511. myDiagram.model.startTransaction("change callbacks");
  512. myDiagram.model.setDataProperty(node.data, "callbacks", editor.getText());
  513. myDiagram.model.commitTransaction("change callbacks");
  514. }
  515. }
  516. if (selectLink) {
  517. let link = myDiagram.findLinkForData(linkData);
  518. if (link) {
  519. myDiagram.model.startTransaction("change callbacks");
  520. myDiagram.model.setDataProperty(link.data, "callbacks", editor.getText());
  521. myDiagram.model.commitTransaction("change callbacks");
  522. }
  523. }
  524. if (!editKey && !selectLink && !multiSelect) {
  525. globalCallbacksText = editor.getText();
  526. }
  527. }
  528. // 修复 bug 当重新加载gojs时恢复init key
  529. let getInitialKeyFromGoJs = function (flowForGoJs) {
  530. let nodeDataArray = flowForGoJs.nodeDataArray;
  531. for (let i = 0, l = nodeDataArray.length; i < l; i++) {
  532. if (nodeDataArray[i].isInit) {
  533. return nodeDataArray[i].key;
  534. }
  535. }
  536. }
  537. window.addEventListener('beforeunload', (event) => {
  538. let postData = {
  539. message: "panelClose",
  540. }
  541. window.parent.postMessage(postData, "*");
  542. });
  543. let handleFiles = function (files) {
  544. let l = 1;
  545. for (var i = 0; i < l; i++) {
  546. var file = files[i];
  547. var reader = new FileReader();
  548. reader.onload = function (e) {
  549. //console.log(reader.result);
  550. //let gojsResult = reader.result.match(/###(.*)###/g)[0];
  551. let gojsResult = /###(.*)###/.exec(reader.result)[1];
  552. let flowForGoJs = JSON.parse(gojsResult);
  553. //let flowForGoJs = JSON.parse(reader.result);
  554. globalCallbacksText = flowForGoJs.globalCallbacksText;
  555. editor.setText(globalCallbacksText);
  556. expandJson();
  557. if (flowForGoJs) {
  558. myDiagram.model = go.Model.fromJson(flowForGoJs);
  559. } else {
  560. notie.removeAll();
  561. notie.alert({type: "error", text: "状态机解析出错", stay: true});
  562. }
  563. };
  564. reader.readAsText(file);
  565. }
  566. }
  567. let helpText =
  568. [
  569. `双击 : 创建状态`,
  570. `alt + q : 切换创建模式与连线模式`,
  571. `alt + c : 设置初始化状态`,
  572. `alt + s : 保存状态机`,
  573. `alt + e : 导出状态机`,
  574. `alt + o : 导入状态机`,
  575. `聚焦资源管理fsm目录下状态机 : 快速导入状态机`,
  576. `属性编辑面板 : 添加状态或事件的方法回调句柄`,
  577. `状态机编辑面板快捷键 : 详情查看 <a href="http://gojs.net/latest/api/index.html">http://gojs.net/latest/api/index.html</a>`,
  578. `属性编辑面板快捷键 : 详情查看 <a href="https://github.com/josdejong/jsoneditor/blob/master/docs/shortcut_keys.md">https://github.com/josdejong/jsoneditor/blob/master/docs/shortcut_keys.md</a>`,
  579. `状态机代码使用方式: 详情查看 <a href="http://www.jianshu.com/p/f4f887426700">http://www.jianshu.com/p/f4f887426700</a>`
  580. ];
  581. let tipsI = 0;
  582. let tipsL = helpText.length;
  583. let generateTipsConfirm = function (idx) {
  584. notie.removeAll();
  585. notie.confirm({
  586. text: helpText[idx],
  587. submitText: "上一条", // optional, default = 'Yes'
  588. cancelText: "下一条", // optional, default = 'Cancel'
  589. position: "top", // optional, default = 'top', enum: ['top', 'bottom']
  590. submitCallback: function () {
  591. generateTipsConfirm((tipsI = (tipsI - 1 + tipsL) % tipsL))
  592. }, // optional
  593. cancelCallback: function () {
  594. generateTipsConfirm((tipsI = (tipsI + 1) % tipsL))
  595. }, // optional
  596. });
  597. }
  598. let getHelp = function () {
  599. generateTipsConfirm(tipsI % tipsL);
  600. }
  601. </script>
  602. </body>
  603. </html>