@cniot/android-pda-components 1.1.11 → 2.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/doc/index.jsx CHANGED
@@ -42,6 +42,7 @@ import systemloading from "../packages/pageflow-system-pages/loading/doc";
42
42
  import BaseLayout from "../packages/BaseLayout/doc.jsx";
43
43
  import useFiled from "../packages/useFiled/doc.jsx";
44
44
 
45
+ import AllV2Components from './all-v2-components/index.jsx'
45
46
  // 系统界面
46
47
  // import PageFlowSystemPages from "../packages/pageflow-system-pages";
47
48
 
@@ -49,7 +50,74 @@ import "./index.less";
49
50
 
50
51
  const docs = [
51
52
  {
52
- title: "组件列表",
53
+ title: '快速开始',
54
+ group: 'start',
55
+ pages: [
56
+ {
57
+ key: "First",
58
+ title: "快速开始",
59
+ doc: First,
60
+ },
61
+ ]
62
+ },
63
+ {
64
+ title: "V2 组件",
65
+ group: 'V2',
66
+ pages: [
67
+ {
68
+ key: "debug",
69
+ title: "debug",
70
+ doc: AllV2Components,
71
+ },
72
+ {
73
+ key: "Header",
74
+ title: "Header",
75
+ doc: Header,
76
+ },
77
+ ],
78
+ },
79
+ {
80
+ title: "内置界面预览",
81
+ pages: [
82
+ {
83
+ key: "/system/alert",
84
+ title: "/system/alert",
85
+ doc: systemAlert,
86
+ },
87
+ {
88
+ key: "/system/confirm",
89
+ title: "/system/confirm",
90
+ doc: systemConfirm,
91
+ },
92
+ {
93
+ key: "/system/toast",
94
+ title: "/system/toast",
95
+ doc: systemToast,
96
+ },
97
+ {
98
+ key: "/system/prompt",
99
+ title: "/system/prompt",
100
+ doc: systemprompt,
101
+ },
102
+ {
103
+ key: "/system/loading",
104
+ title: "/system/loading",
105
+ doc: systemloading,
106
+ },
107
+ ],
108
+ },
109
+ {
110
+ title: "布局容器",
111
+ pages: [
112
+ {
113
+ key: "BaseLayout",
114
+ title: "BaseLayout",
115
+ doc: BaseLayout,
116
+ },
117
+ ],
118
+ },
119
+ {
120
+ title: "组件列表-V1",
53
121
  pages: [
54
122
  {
55
123
  key: "First",
@@ -224,46 +292,6 @@ const docs = [
224
292
  },
225
293
  ],
226
294
  },
227
- {
228
- title: "内置界面预览",
229
- pages: [
230
- {
231
- key: "/system/alert",
232
- title: "/system/alert",
233
- doc: systemAlert,
234
- },
235
- {
236
- key: "/system/confirm",
237
- title: "/system/confirm",
238
- doc: systemConfirm,
239
- },
240
- {
241
- key: "/system/toast",
242
- title: "/system/toast",
243
- doc: systemToast,
244
- },
245
- {
246
- key: "/system/prompt",
247
- title: "/system/prompt",
248
- doc: systemprompt,
249
- },
250
- {
251
- key: "/system/loading",
252
- title: "/system/loading",
253
- doc: systemloading,
254
- },
255
- ],
256
- },
257
- {
258
- title: "布局容器",
259
- pages: [
260
- {
261
- key: "BaseLayout",
262
- title: "BaseLayout",
263
- doc: BaseLayout,
264
- },
265
- ],
266
- },
267
295
  ];
268
296
 
269
297
  function getDoc(key) {
@@ -282,6 +310,7 @@ function getHashKey() {
282
310
 
283
311
  function App() {
284
312
  const [currentIndex, setCurrentIndex] = React.useState(getHashKey);
313
+ const [groupTitleHeight, setGroupTitleHeight] = React.useState(46);
285
314
  const onClickComponentItem = React.useCallback(function (key) {
286
315
  location.hash = key;
287
316
  // setCurrentIndex(key);
@@ -290,6 +319,8 @@ function App() {
290
319
  window.addEventListener("hashchange", function () {
291
320
  setCurrentIndex(getHashKey());
292
321
  });
322
+
323
+ setGroupTitleHeight(document.getElementsByClassName('doc-group-title')?.[0]?.offsetHeight)
293
324
  }, []);
294
325
 
295
326
  const currentDoc = getDoc(currentIndex);
@@ -307,27 +338,39 @@ function App() {
307
338
  {docs.map(function (item, index) {
308
339
  return (
309
340
  <React.Fragment key={index}>
310
- <h2>{item.title}</h2>
311
- {item.pages.map(function (item) {
312
- return (
313
- <div
314
- className={
315
- currentIndex === item.key
316
- ? "components-item active"
317
- : "components-item"
318
- }
319
- onClick={onClickComponentItem.bind(null, item.key)}
320
- data-index={item.key}
321
- key={item.key}
322
- >
323
- {item.abandon ? (
324
- <s>{item.title}</s>
325
- ) : (
326
- <span>{item.title}</span>
327
- )}
328
- </div>
329
- );
330
- })}
341
+ <div className='doc-group-title' style={{ top: -20 + index * groupTitleHeight }}
342
+ onClick={(e) => {
343
+ const div1 = document.querySelector(`div[data-group="${index}"]`)
344
+ div1?.setAttribute?.('style', `display:${div1.offsetHeight === 0 ? 'block' : 'none'}`);
345
+
346
+ const div2 = document.querySelector(`div[data-group-fold="${index}"]`);
347
+ div2.innerHTML && (div2.innerHTML = div2.innerHTML === '点击收起' ? '点击展开' : '点击收起');
348
+ }}>
349
+ <h2 >{item.title}</h2>
350
+ <div data-group-fold={index} className="doc-group-fold">{['V2', 'start'].includes(item.group) ? '点击收起' : '点击展开'}</div>
351
+ </div>
352
+ <div data-group={index} style={{ display: `${['V2', 'start'].includes(item.group) ? 'block' : 'none'}` }}>
353
+ {item.pages.map(function (item) {
354
+ return (
355
+ <div
356
+ className={
357
+ currentIndex === item.key
358
+ ? "components-item active"
359
+ : "components-item"
360
+ }
361
+ onClick={onClickComponentItem.bind(null, item.key)}
362
+ data-index={item.key}
363
+ key={item.key}
364
+ >
365
+ {item.abandon ? (
366
+ <s>{item.title}</s>
367
+ ) : (
368
+ <span>{item.title}</span>
369
+ )}
370
+ </div>
371
+ );
372
+ })}
373
+ </div>
331
374
  </React.Fragment>
332
375
  );
333
376
  })}
package/doc/index.less CHANGED
@@ -1,50 +1,78 @@
1
1
  .components-container {
2
2
  display: flex;
3
+ height: 100vh;
3
4
  }
5
+
4
6
  .components-example {
5
7
  flex-direction: column;
6
8
  border-right: 1px solid #d8d8d8;
7
9
  min-height: 100vh;
8
10
  padding-right: 10px;
11
+ overflow-y: scroll;
12
+ width: 260px;
13
+ padding: 16px;
14
+ background-color: #ffffff;
15
+
16
+ .doc-group-title {
17
+ display: flex;
18
+ align-items: flex-end;
19
+ border-bottom: 1px solid #d8d8d8;
20
+ cursor: pointer;
21
+ position: sticky;
22
+ top: -20px;
23
+ background-color: #fff;
24
+
25
+
26
+ .doc-group-fold {
27
+ padding-bottom: 5px;
28
+ color: #6d67f1;
29
+ }
30
+
9
31
  h1 {
10
32
  margin-top: 20px;
11
33
  }
34
+
12
35
  h2 {
36
+ flex: 1;
13
37
  color: #00000073;
14
38
  font-size: 14px;
15
39
  margin-top: 20px;
16
- border-bottom: 1px solid #d8d8d8;
40
+ // border-bottom: 1px solid #d8d8d8;
17
41
  padding-bottom: 5px;
18
42
  }
43
+ }
44
+
45
+ .components-item {
46
+ color: #000000d9;
47
+ font-size: 16px;
48
+ padding: 10px 0;
49
+ margin-left: 20px;
50
+ align-items: center;
51
+ cursor: pointer;
52
+
53
+ &:hover,
54
+ &.active {
55
+ color: #4f10fd73;
56
+ }
19
57
 
20
- .components-item {
21
- color: #000000d9;
22
- font-size: 16px;
23
- padding: 10px 0;
24
- margin-left: 20px;
25
- align-items: center;
26
- cursor: pointer;
27
- &:hover,
28
- &.active {
29
- color: #4f10fd73;
30
- }
31
-
32
- > small {
33
- margin-left: 1em;
34
- }
58
+ >small {
59
+ margin-left: 1em;
35
60
  }
36
61
  }
62
+ }
37
63
 
38
64
  .show-case {
39
65
  display: flex;
40
66
  flex-direction: column;
41
67
  padding: 50px;
42
68
  flex: 1;
69
+ overflow: auto;
43
70
 
44
71
  h2 {
45
72
  // font-size: 80%;
46
73
  margin: 20px 0;
47
74
  }
75
+
48
76
  .code {
49
77
  white-space: pre;
50
78
  border: 1px solid #e8e8e8;
@@ -53,6 +81,7 @@
53
81
  padding: 5px 10px;
54
82
  display: block;
55
83
  margin: 20px 0;
84
+ text-wrap: wrap
56
85
  }
57
86
  }
58
87
 
@@ -106,7 +135,7 @@ th {
106
135
  border-bottom: 1px solid #cbcbcb;
107
136
  }
108
137
 
109
- .pure-table-bordered tbody > tr:last-child > td {
138
+ .pure-table-bordered tbody>tr:last-child>td {
110
139
  border-bottom-width: 0;
111
140
  }
112
141
 
@@ -117,6 +146,7 @@ th {
117
146
  border: 1px solid #e9e9e9;
118
147
  border-radius: 6px;
119
148
  flex-direction: column;
149
+
120
150
  &:not(:last-child) {
121
151
  margin-bottom: 20px;
122
152
  }
@@ -131,9 +161,11 @@ th {
131
161
  background-color: black;
132
162
  padding: 24px;
133
163
  }
164
+
134
165
  .light-block {
135
166
  background-color: #ddd;
136
167
  padding: 24px;
168
+
137
169
  &.pda {
138
170
  width: 50%;
139
171
  }
@@ -142,9 +174,11 @@ th {
142
174
  .light-block-overlay {
143
175
  position: relative;
144
176
  height: 300px;
177
+
145
178
  .op-overlay {
146
179
  position: absolute !important;
147
180
  }
181
+
148
182
  .op-overlay::before {
149
183
  position: absolute !important;
150
184
  width: 100% !important;
@@ -0,0 +1,46 @@
1
+ import Flow from "@cniot/flow";
2
+ import UI, { alert, confirm, toast, prompt, historyBack } from "./pages";
3
+
4
+ export const appId = UI.channel.flowId;
5
+ // 流程入口
6
+ export async function onStart() {
7
+ const flow = new Flow(UI);
8
+
9
+ flow.data = {};
10
+
11
+ flow.push(test);
12
+
13
+ flow.catch(async function (e) {
14
+ await alert(e.message, "", "Retry");
15
+ return flow.replay();
16
+ });
17
+
18
+ flow.start({});
19
+ }
20
+
21
+ async function test(data, flow) {
22
+ const input = await UI.router("/pages/scan", {});
23
+ if (flow.isBack(input)) {
24
+ return historyBack();
25
+ }
26
+ if (input === "prompt") {
27
+ await prompt("title", "placeholder", "defaultValue", "ok", "cancel");
28
+ }
29
+ if (input === "alert") {
30
+ await alert("alert", "message", "ok");
31
+ }
32
+ if (input === "confirm") {
33
+ await confirm("title", "message", "oktext", "cancelText");
34
+ }
35
+ if (input === "success") {
36
+ await toast("title", "message", "success", 2000);
37
+ }
38
+ if (input === "error") {
39
+ await toast("title", "message", "error", 2000);
40
+ }
41
+
42
+ if (input === "popup") {
43
+ await UI.overlay("/pages/popup", {});
44
+ }
45
+ return flow.next({});
46
+ }
@@ -0,0 +1,82 @@
1
+ import i18n from "$src/i18n"; // import $i18n from "$i18n";
2
+ import { UserInterface } from "@cniot/pageflow";
3
+ // ---
4
+ const UI = UserInterface.create();
5
+
6
+ export default UI;
7
+
8
+ /**
9
+ * 通用页面 toast
10
+ * PC 文档: https://page.cainiao.com/lemo/op-components/index.html#/system/toast
11
+ * RF 文档: https://page.cainiao.com/lemo/android-pda-components/index.html#/system/toast
12
+ * level: "error", "warning", "success"
13
+ */
14
+ export function toast(
15
+ title = "",
16
+ message = "",
17
+ level = "error",
18
+ duration = 5000
19
+ ) {
20
+ return UI.toast("/system/toast", { title, message, level, duration });
21
+ }
22
+
23
+ /**
24
+ * 通用页面 alert
25
+ * PC 文档: https://page.cainiao.com/lemo/op-components/index.html#/system/alert
26
+ * RF 文档: https://page.cainiao.com/lemo/android-pda-components/index.html#/system/alert
27
+ */
28
+ export function alert(
29
+ title = "",
30
+ message = "",
31
+ okText = $i18n.get({
32
+ id: "tempalte.flow.service.pages.Determine",
33
+ dm: i18n.get("确定"),
34
+ })
35
+ ) {
36
+ return UI.overlay("/system/alert", { title, message, okText });
37
+ }
38
+
39
+ /**
40
+ * 通用页面 confirm
41
+ * PC 文档: https://page.cainiao.com/lemo/op-components/index.html#/system/confirm
42
+ * RF 文档: https://page.cainiao.com/lemo/android-pda-components/index.html#/system/confirm
43
+ */
44
+ export function confirm(
45
+ title = $i18n.get(i18n.get("请确认")),
46
+ message = $i18n.get(i18n.get("点击确认完成操作")),
47
+ okText = $i18n.get(i18n.get("确认")),
48
+ cancelText = $i18n.get(i18n.get("取消"))
49
+ ) {
50
+ return UI.overlay("/system/confirm", { title, message, okText, cancelText });
51
+ }
52
+
53
+ /**
54
+ * 通用页面 prompt
55
+ * PC 文档: https://page.cainiao.com/lemo/op-components/index.html#/system/prompt
56
+ * RF 文档: https://page.cainiao.com/lemo/android-pda-components/index.html#/system/prompt
57
+ */
58
+ export function prompt(
59
+ title = $i18n.get(i18n.get("请输入")),
60
+ placeholder = $i18n.get(i18n.get("请输入")),
61
+ defaultValue = "",
62
+ okText = $i18n.get(i18n.get("确认")),
63
+ cancelText = $i18n.get(i18n.get("取消"))
64
+ ) {
65
+ return UI.overlay("/system/prompt", {
66
+ title,
67
+ placeholder,
68
+ defaultValue,
69
+ okText,
70
+ cancelText,
71
+ });
72
+ }
73
+
74
+ // 调用浏览器back
75
+ export function historyBack() {
76
+ return UI.logic("/system/historyBack");
77
+ }
78
+
79
+ // 获取url参数
80
+ export function getSearchQuery() {
81
+ return UI.logic("/system/getSearchQuery");
82
+ }
@@ -0,0 +1,37 @@
1
+ import { cookie } from "@aligov/global-locale";
2
+
3
+ /**
4
+ * 程序进入等待状态 delay 秒后执行后面的代码
5
+ * @param {*} delay
6
+ * @returns
7
+ */
8
+ export function sleep(delay = 1000) {
9
+ return new Promise(function (resolve, reject) {
10
+ setTimeout(function () {
11
+ resolve(true);
12
+ }, delay);
13
+ });
14
+ }
15
+
16
+ /**
17
+ * 判断是否是系统错误
18
+ */
19
+ export function isSystemError(err) {
20
+ return (
21
+ err instanceof EvalError ||
22
+ err instanceof RangeError ||
23
+ err instanceof ReferenceError ||
24
+ err instanceof SyntaxError ||
25
+ err instanceof TypeError ||
26
+ err instanceof URIError
27
+ );
28
+ }
29
+
30
+ /**
31
+ * 导出cookie的操作方法
32
+ * cookie.get(key);
33
+ * cookie.set(key);
34
+ */
35
+ export const Cookie = {
36
+ ...cookie,
37
+ };
@@ -0,0 +1,95 @@
1
+ /*
2
+ * This file is generated by parrot must
3
+ * DOCUMENT LIST:
4
+ * parrot must: http://gitlab.alibaba-inc.com/parrot/parrot-tool-must
5
+ * @ali/global-locale: http://gitlab.alibaba-inc.com/parrot/global-locale
6
+ * @ali/global-string-format: http://gitlab.alibaba-inc.com/parrot/global-string-format
7
+ */
8
+ import i18n from "$i18n";
9
+ import locale from "@aligov/global-locale";
10
+ import stringFormat from "@aligov/global-string-format";
11
+ import strings from "./strings";
12
+
13
+ let language; // Current language
14
+ let intl; // Instance of intl-universal. Create by provideIntl
15
+ /**
16
+ * update instance of intl universal
17
+ */
18
+ function update() {
19
+ const { lang } = locale.getLocale();
20
+ language = lang;
21
+ intl = stringFormat.init(lang, strings);
22
+ }
23
+
24
+ /**
25
+ * change current language
26
+ * @param {string} langTag language tag config above
27
+ */
28
+ function change(langTag) {
29
+ locale.setLang(langTag);
30
+ update();
31
+ }
32
+ /**
33
+ * Format string by key
34
+ * For example:
35
+ * $i18n.get('jsx.home.title'),
36
+ * $i18n.get({
37
+ * id: 'jsx.home.hello',
38
+ * defaultMessage: 'Hello {name}' // not required
39
+ * },{
40
+ * name: 'Alice'
41
+ * })
42
+ * More syntax: https://formatjs.io/guides/message-syntax/
43
+ * @param {string|object} id key or object
44
+ * @param {object} variable variable for id
45
+ * @return {string} format message
46
+ */
47
+ function get(id, variable) {
48
+ if (!intl) update();
49
+ if (typeof id === "string") {
50
+ return stringFormat.format(
51
+ {
52
+ id: id,
53
+ },
54
+ variable
55
+ );
56
+ } else if (typeof id === "object" && id.dm) {
57
+ id.defaultMessage = id.dm;
58
+ }
59
+ return stringFormat.format(
60
+ {
61
+ id: id.id,
62
+ defaultString: id.dm,
63
+ },
64
+ variable
65
+ );
66
+ }
67
+
68
+ function addMessage(strs) {
69
+ for (let key in strs) {
70
+ if (!strings[key]) {
71
+ strings[key] = {};
72
+ }
73
+ Object.assign(strings[key], strs[key]);
74
+ }
75
+ }
76
+
77
+ /* set the first hng cookie
78
+ * //! IMPORTANT remove this after published, only for demo to start up
79
+ * //! IMPORTANT 项目第一次启动后请删除下边的逻辑,这个逻辑只是为了第一次运行的时候,项目能够切换到英文
80
+ */
81
+ // Delete start
82
+ // change("en-US");
83
+ // change("zh-CN");
84
+ // Delete end
85
+
86
+ i18n.addMessage(strings);
87
+ // window.locale = locale;
88
+ export default {
89
+ get,
90
+ update,
91
+ change,
92
+ language,
93
+ locale,
94
+ addMessage,
95
+ };
@@ -0,0 +1 @@
1
+ {}
@@ -0,0 +1,8 @@
1
+
2
+ import enUS from './en-US';
3
+ import zhCN from './zh-CN';
4
+
5
+ export default {
6
+ "en-US": enUS,
7
+ "zh-CN": zhCN,
8
+ };
@@ -0,0 +1 @@
1
+ {}
@@ -0,0 +1,46 @@
1
+ import React from "react";
2
+ import { PageFlowApp, WebService, Desktop } from "@cniot/pageflow";
3
+ import { appId, onStart } from "./flow";
4
+ import track from "../../track";
5
+
6
+ // 使用 PC 组件库,开发基于 pc 的实操流程
7
+ import registerSystemPages from "../../system/index-android-pda";
8
+ // 使用 android 组件库,开发基于 手机浏览器的 的实操流程
9
+ // import registerSystemPages from "../../system/index-pc";
10
+ // import "./index.less";
11
+
12
+ // 创建链接 GS 的服务程序
13
+ const service = new WebService({
14
+ // 应用id
15
+ appId,
16
+ // 启动函数
17
+ onStart,
18
+ debug: true,
19
+ });
20
+
21
+ const app = new PageFlowApp({
22
+ service,
23
+ // 如果下发了没有定义的页面,会显示这个 404
24
+ notFoundPage: "/system/404",
25
+ // 如果 gs 中使用 new Error() 抛出错误,会调用 showErrorPagePath 定义的页面
26
+ showErrorPage: "/system/toast",
27
+ });
28
+
29
+ // 注册组件库提供的默认界面,用法请参考组件库文档
30
+ registerSystemPages(app);
31
+
32
+ // 自动监控每个页面第一次渲染时间,同时支持按钮点击统计
33
+ track(app);
34
+
35
+ // 自动注册的web/pages下 index.jsx 的页面, 注册路径同文件夹保持一致
36
+ const pages = import.meta.globEager("./pages/*/index.jsx");
37
+ Object.keys(pages).forEach(function (key) {
38
+ const mpath = key.match(/(\/pages\/.+)\//);
39
+ if (mpath && mpath[1]) {
40
+ app.registerPage(mpath[1], pages[key].default);
41
+ }
42
+ });
43
+
44
+ export default function () {
45
+ return <Desktop app={app} service={service} />;
46
+ }
@@ -0,0 +1,22 @@
1
+ import React from "react";
2
+ import { Button, List } from "antd-mobile";
3
+ import { Layout, Header, Footer, Scan, Popup } from "$src/components";
4
+ /**
5
+ * 标准 React 组件
6
+ * @param data any 指令下发的数据
7
+ * @param onNext 把数据回传给流程控制
8
+ * @param onCallback 一个特殊的回传值的方法,可以传2个参数,在flow.onCallback里统一接收
9
+ * @param hasActive() 当前页面是否在激活状态,如果弹出 overlay 的页面 hasActive 会变成 false
10
+ * @return React.Element
11
+ */
12
+ export default function (props) {
13
+ const { data, onNext } = props;
14
+ return (
15
+ <Popup visible={true} onClose={() => onNext()}>
16
+ <div>12312321</div>
17
+ <Button block color="primary" onClick={() => onNext()}>
18
+ 按钮组
19
+ </Button>
20
+ </Popup>
21
+ );
22
+ }
File without changes