@ticatec/uniface-element 0.3.7 → 0.3.9

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.
@@ -11,6 +11,7 @@
11
11
  import ActionPanel from "./parts/ActionsPanel.svelte";
12
12
  import {OrderDirection} from "./lib/OrderDirection";
13
13
  import type {CompareFunction} from "./lib/CompareFunction";
14
+ import type {GetRowFontStyle} from "./lib/types";
14
15
 
15
16
  export let columns: Array<DataColumn>;
16
17
  export let actionsColumn: ActionsColumn | null = null;
@@ -22,6 +23,7 @@
22
23
  export let rowBorder: boolean = false;
23
24
  export let colBorder: boolean = false;
24
25
  export let emptyIndicator: string | undefined = undefined;
26
+ export let getRowFontStyle: GetRowFontStyle | undefined = undefined;
25
27
 
26
28
  export let style: string = '';
27
29
 
@@ -114,7 +116,7 @@
114
116
  <ContentPanel columns={dataColumns} {orderDirection} {orderColumn} {handleWidthChange} {handleCellClick} {tabWidth} bind:rows
115
117
  bind:scrollTop {expandRow} {rowHeight} {list} {table} {inlineComponent} bind:inlineRowHeight {emptyIndicator}
116
118
  displayHorizontalScroll={actionsColumn!=null || indicatorColumn != null || fixedCols.length > 0}
117
- showVerticalScroll={actionsColumn == null}/>
119
+ showVerticalScroll={actionsColumn == null} {getRowFontStyle}/>
118
120
  {/if}
119
121
 
120
122
  {#if actionsColumn}
@@ -1,6 +1,7 @@
1
1
  import type DataColumn from "./lib/DataColumn";
2
2
  import type ActionsColumn from "./lib/ActionsColumn";
3
3
  import type IndicatorColumn from "./lib/IndicatorColumn";
4
+ import type { GetRowFontStyle } from "./lib/types";
4
5
  interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
5
6
  new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
6
7
  $$bindings?: Bindings;
@@ -25,6 +26,7 @@ declare const DataTable: $$__sveltets_2_IsomorphicComponent<{
25
26
  rowBorder?: boolean;
26
27
  colBorder?: boolean;
27
28
  emptyIndicator?: string | undefined;
29
+ getRowFontStyle?: GetRowFontStyle | undefined;
28
30
  style?: string;
29
31
  }, {
30
32
  [evt: string]: CustomEvent<any>;
@@ -1,6 +1,7 @@
1
1
  import type { CellHint, FormatCell } from "./FormatCell";
2
2
  import type { HrefBuilder } from "./HrefLink";
3
3
  import type { CompareFunction } from "./CompareFunction";
4
+ import type { GetCellStyle } from "./types";
4
5
  export default interface DataColumn {
5
6
  /**
6
7
  * 列头文字
@@ -59,4 +60,8 @@ export default interface DataColumn {
59
60
  *
60
61
  */
61
62
  compareFunction?: CompareFunction;
63
+ /**
64
+ * 获取表格的样式
65
+ */
66
+ cellStyle?: GetCellStyle;
62
67
  }
@@ -0,0 +1,22 @@
1
+ export interface RowFontStyle {
2
+ /**
3
+ * 字体大小
4
+ */
5
+ size?: string;
6
+ /**
7
+ * 字体颜色
8
+ */
9
+ color?: string;
10
+ /**
11
+ * 字重
12
+ */
13
+ weight?: number | string;
14
+ }
15
+ /**
16
+ * 获取cell样式
17
+ */
18
+ export type GetCellStyle = (data: any) => string;
19
+ /**
20
+ * 获取整行的样式
21
+ */
22
+ export type GetRowFontStyle = (data: any) => RowFontStyle;
@@ -0,0 +1 @@
1
+ export {};
@@ -7,6 +7,7 @@
7
7
  import TableHeaderPanel from "./TableHeaderPanel.svelte";
8
8
  import UniDataTable, {type TableEventHandler} from "../UniDataTable";
9
9
  import {OrderDirection} from "../lib/OrderDirection";
10
+ import type {GetRowFontStyle} from "../lib/types";
10
11
 
11
12
 
12
13
  export let columns: Array<DataColumn>;
@@ -14,6 +15,8 @@
14
15
  export let orderColumn: DataColumn ;
15
16
  export let orderDirection: OrderDirection;
16
17
 
18
+ export let getRowFontStyle: GetRowFontStyle | undefined;
19
+
17
20
  export let emptyIndicator: string | null = null;
18
21
 
19
22
  export let list: Array<any>;
@@ -121,7 +124,7 @@
121
124
  {#if rows && rows.length > 0}
122
125
  <div style="box-sizing: border-box; width: {rowWidth}px; top: {top}">
123
126
  {#each rows as row, idx}
124
- <DataRow {rowHeight} {row} {columns} alternative={idx % 2 == 1}/>
127
+ <DataRow fontStyle={getRowFontStyle?.(row.data)} {rowHeight} {row} {columns} alternative={idx % 2 == 1}/>
125
128
  {#if row == expandRow && inlineComponent}
126
129
  <div class="expand-data-row" bind:clientHeight={inlineRowHeight}
127
130
  style="position: relative; box-sizing: content-box; width: 100%; height: auto">
@@ -2,6 +2,7 @@ import type DataColumn from "../lib/DataColumn";
2
2
  import type TableRow from "./TableRow";
3
3
  import UniDataTable, { type TableEventHandler } from "../UniDataTable";
4
4
  import { OrderDirection } from "../lib/OrderDirection";
5
+ import type { GetRowFontStyle } from "../lib/types";
5
6
  interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
6
7
  new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
7
8
  $$bindings?: Bindings;
@@ -20,6 +21,7 @@ declare const ContentPanel: $$__sveltets_2_IsomorphicComponent<{
20
21
  rows: Array<TableRow>;
21
22
  orderColumn: DataColumn;
22
23
  orderDirection: OrderDirection;
24
+ getRowFontStyle: GetRowFontStyle | undefined;
23
25
  emptyIndicator?: string | null;
24
26
  list: Array<any>;
25
27
  expandRow: TableRow | null;
@@ -13,15 +13,17 @@
13
13
  let hint: any;
14
14
  let cell: any;
15
15
  let col$class: string ='';
16
+ let style: string = '';
16
17
 
17
18
  $: {
18
19
  hint = column.hint?.(data);
20
+ style = column.cellStyle?.(data) ?? '';
19
21
  }
20
22
 
21
23
  $: col$class = frozen ? `fz_col-${colIdx}` : `col-${colIdx}`;
22
24
 
23
25
  </script>
24
- <div class="data-cell {col$class}">
26
+ <div class="data-cell {col$class}" {style}>
25
27
  <div class="vertical-center">
26
28
  {#if column.render}
27
29
  <svelte:component this={column.render.component} {...column.render.props} {data}/>
@@ -3,15 +3,37 @@
3
3
  import type DataColumn from "../lib/DataColumn";
4
4
  import DataCell from "./DataCell.svelte";
5
5
  import type TableRow from "./TableRow";
6
+ import type {RowFontStyle} from "../lib/types";
6
7
 
7
8
  export let columns: Array<DataColumn>;
8
9
  export let row: TableRow;
9
10
  export let alternative: boolean;
10
- export let rowHeight: number; //{ rowHeight}
11
-
12
- let style: string = '';
13
-
14
- $: style = rowHeight== null ? '' : `height: ${rowHeight}px`
11
+ export let rowHeight: number;
12
+ export let fontStyle: RowFontStyle;
13
+
14
+ /**
15
+ * 获取行样式
16
+ * @param rh
17
+ * @param fs
18
+ */
19
+ const getRowStyle = (rh: number, fs: RowFontStyle) => {
20
+ let rs = '';
21
+ if (rh) {
22
+ rs = `height: ${rowHeight}px`;
23
+ }
24
+ if (fs?.size) {
25
+ rs = `font-size: ${fs.size}; ${rs}`;
26
+ }
27
+ if (fs?.color) {
28
+ rs = `color: ${fs?.color}; ${rs}`;
29
+ }
30
+ if (fs?.weight) {
31
+ rs = `font-weight: ${fs?.weight}; ${rs}`;
32
+ }
33
+ return rs;
34
+ }
35
+
36
+ $: style = getRowStyle(rowHeight, fontStyle)
15
37
 
16
38
 
17
39
  </script>
@@ -1,5 +1,6 @@
1
1
  import type DataColumn from "../lib/DataColumn";
2
2
  import type TableRow from "./TableRow";
3
+ import type { RowFontStyle } from "../lib/types";
3
4
  interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
4
5
  new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
5
6
  $$bindings?: Bindings;
@@ -18,6 +19,7 @@ declare const DataRow: $$__sveltets_2_IsomorphicComponent<{
18
19
  row: TableRow;
19
20
  alternative: boolean;
20
21
  rowHeight: number;
22
+ fontStyle: RowFontStyle;
21
23
  }, {
22
24
  [evt: string]: CustomEvent<any>;
23
25
  }, {}, {}, string>;
@@ -1,11 +1,11 @@
1
1
  <script lang="ts">
2
2
 
3
- import {DisplayMode} from "../common/DisplayMode";
4
- import type {OnChangeHandler} from "../common/OnChangeHandler";
5
- import {tick} from "svelte";
3
+ import {DisplayMode} from "../types";
4
+ import type {OnChangeHandler} from "../types";
6
5
  import CommonPicker from "../common/CommonPicker.svelte";
7
6
  import loadingGif from "../assets/loading.gif";
8
- import type {LazyLoader} from "../list-box/types";
7
+ import type {LazyLoader} from "../types";
8
+ import type {RetrieveOptionText} from "../types";
9
9
 
10
10
  export let variant: '' | 'plain' | 'outlined' | 'filled' = '';
11
11
  export let disabled: boolean = false;
@@ -14,7 +14,8 @@
14
14
  export let text: string = '';
15
15
  export let value: any = null;
16
16
  export let keyField: string = "code";
17
- export let textField: string = "text";
17
+ export let textField: string | undefined = undefined;
18
+ export let retrieveText: RetrieveOptionText | undefined = undefined;
18
19
  export let displayCode: boolean = false;
19
20
  export let menu$height: number = 0;
20
21
  export let style: string = '';
@@ -150,10 +151,14 @@
150
151
  const handleItemClick = (data: any) => () => {
151
152
  isUserTyping = false;
152
153
  value = data[keyField];
153
- text = data[textField];
154
154
  if (value != oldValue) {
155
155
  onchange?.(data);
156
156
  }
157
+ if (retrieveText) {
158
+ text = retrieveText(data)
159
+ } else if (textField) {
160
+ text = data[textField]
161
+ }
157
162
  editor.focus();
158
163
  showPopup = false;
159
164
  }
@@ -194,7 +199,6 @@
194
199
  const handleBlur = (event: FocusEvent) => {
195
200
  setTimeout(() => {
196
201
  const focused = scrollElement!=null && scrollElement.contains(document.activeElement);
197
- console.log('当前组合组件是否聚集', focused, value)
198
202
  if (!focused) {
199
203
  hasFocus = false;
200
204
  if (value == null) {
@@ -205,6 +209,10 @@
205
209
  }, 50)
206
210
  };
207
211
 
212
+ const getDisplayText = (item: any) => {
213
+ return retrieveText?.(item) ?? item[textField ?? keyField];
214
+ }
215
+
208
216
  const clean = () => {
209
217
  value = null;
210
218
  text = '';
@@ -230,7 +238,7 @@
230
238
  // 如果已选择值,根据焦点状态显示keyField或textField
231
239
  let selectedItem = options.find(op => op[keyField] == value);
232
240
  if (selectedItem) {
233
- inputText = hasFocus && displayCode ? selectedItem[keyField] : selectedItem[textField];
241
+ inputText = hasFocus && displayCode ? selectedItem[keyField] : getDisplayText(selectedItem);
234
242
  } else {
235
243
  inputText = hasFocus && displayCode ? value : text;
236
244
  }
@@ -279,7 +287,7 @@
279
287
  <svelte:component this={itemRender} item={op}/>
280
288
  {:else}
281
289
  <div style="padding: 6px 8px">
282
- <span>{op[textField]}</span>
290
+ <span>{getDisplayText(op)}</span>
283
291
  </div>
284
292
  {/if}
285
293
  </div>
@@ -1,6 +1,7 @@
1
- import { DisplayMode } from "../common/DisplayMode";
2
- import type { OnChangeHandler } from "../common/OnChangeHandler";
3
- import type { LazyLoader } from "../list-box/types";
1
+ import { DisplayMode } from "../types";
2
+ import type { OnChangeHandler } from "../types";
3
+ import type { LazyLoader } from "../types";
4
+ import type { RetrieveOptionText } from "../types";
4
5
  interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
5
6
  new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
6
7
  $$bindings?: Bindings;
@@ -22,7 +23,8 @@ declare const InputOptionsSelect: $$__sveltets_2_IsomorphicComponent<{
22
23
  text?: string;
23
24
  value?: any;
24
25
  keyField?: string;
25
- textField?: string;
26
+ textField?: string | undefined;
27
+ retrieveText?: RetrieveOptionText | undefined;
26
28
  displayCode?: boolean;
27
29
  menu$height?: number;
28
30
  style?: string;
@@ -1,2 +1,4 @@
1
1
  import InputOptionsSelect from "./InputOptionsSelect.svelte";
2
+ import type { RetrieveOptionText } from "./types";
2
3
  export default InputOptionsSelect;
4
+ export type { RetrieveOptionText };
@@ -0,0 +1 @@
1
+ export type {};
@@ -0,0 +1 @@
1
+ export {};
@@ -28,12 +28,11 @@
28
28
  export let onSelectChange: OnSelectChange = null as unknown as OnSelectChange;
29
29
  export let onItemDblClick: OnItemDblClick = null as unknown as OnItemDblClick;
30
30
  export let onItemClick: OnItemClick = null as unknown as OnItemDblClick;
31
-
32
31
  export let title: string = null as unknown as string;
33
32
  export let round: boolean = false;
34
33
  export let footer$style: string | null = null;
34
+ export let filterText: string = '';
35
35
 
36
- let filterText: string;
37
36
  let hasMore: boolean;
38
37
  let isBusy: boolean = false;
39
38
  let pageNo: number = 1;
@@ -146,8 +145,6 @@
146
145
 
147
146
  onMount(async () => {
148
147
  if (lazyLoader != null) {
149
- console.log('加载数据...')
150
- filterText = '';
151
148
  await lazyLoad();
152
149
  }
153
150
  })
@@ -32,6 +32,7 @@ declare const ListBox: $$__sveltets_2_IsomorphicComponent<{
32
32
  title?: string;
33
33
  round?: boolean;
34
34
  footer$style?: string | null;
35
+ filterText?: string;
35
36
  }, {
36
37
  [evt: string]: CustomEvent<any>;
37
38
  }, {
@@ -40,8 +40,9 @@
40
40
  editor.setFocus();
41
41
  }
42
42
 
43
- let textValue: string = utils.formatNumber(value, precision);
43
+ //let textValue: string = utils.formatNumber(value, precision);
44
44
 
45
+ $: textValue = utils.formatNumber(value, precision);
45
46
 
46
47
  </script>
47
48
  <CommonEditor {displayMode} {style} value={textValue} {suffix} {prefix} {readonly} {variant} {compact} class={className}
package/dist/types.d.ts CHANGED
@@ -3,5 +3,11 @@ import type { MouseClickHandler } from "./common/MouseClickHandler";
3
3
  import { DisplayMode } from "./common/DisplayMode.js";
4
4
  import { DateContext } from "./base-calendar";
5
5
  import { ModalResult } from "./message-box";
6
+ import type { LazyLoader } from "./list-box";
7
+ /**
8
+ * 从选中的Option中获取对于的文字值
9
+ */
10
+ type RetrieveOptionText = (item: any) => string;
6
11
  export { DateContext, ModalResult, DisplayMode };
12
+ export type { RetrieveOptionText, LazyLoader };
7
13
  export type { OnChangeHandler, MouseClickHandler };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ticatec/uniface-element",
3
- "version": "0.3.7",
3
+ "version": "0.3.9",
4
4
  "description": "A comprehensive UI component library for Svelte applications with rich form controls, data tables, layouts and interactive elements",
5
5
  "keywords": [
6
6
  "svelte",