htui-yllkbz 1.2.14 → 1.2.18

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.
@@ -5,7 +5,7 @@
5
5
  * @Author: hutao
6
6
  * @Date: 2021-11-11 11:23:24
7
7
  * @LastEditors: hutao
8
- * @LastEditTime: 2021-12-09 16:33:39
8
+ * @LastEditTime: 2021-12-12 09:07:39
9
9
  -->
10
10
  <template>
11
11
  <div v-loading="state.loading">
@@ -65,8 +65,8 @@
65
65
  <slot :name="item.key"
66
66
  :row="row"
67
67
  :column="column"
68
- :rowIndex="rowIndex">{{row[item.key]}}</slot>
69
- {{item.headerSlot}}
68
+ :rowIndex="rowIndex">{{getPropByPath(row,item.key)}}</slot>
69
+
70
70
  </template>
71
71
  <template slot-scope="{column,$index}"
72
72
  slot="header">
@@ -102,11 +102,12 @@ interface State {
102
102
  loading: boolean;
103
103
  }
104
104
  @Component({
105
+ name: "HtTable",
105
106
  components: {
106
107
  PageInfo,
107
108
  },
108
109
  })
109
- export default class Index extends Vue {
110
+ export default class HtTable extends Vue {
110
111
  /** 默认的table头 */
111
112
  @Prop() columns!: Column[];
112
113
  @Prop() data!: any[];
@@ -142,7 +143,56 @@ export default class Index extends Vue {
142
143
  // console.log("this", this.$props);
143
144
  this.setPageInfo(this.pageInfo);
144
145
  }
146
+ getPropByPath(obj: any, path: string, strict: boolean) {
147
+ let tempObj = obj;
148
+ path = path.replace(/\[(\w+)\]/g, ".$1");
149
+ path = path.replace(/^\./, "");
145
150
 
151
+ const keyArr = path.split(".");
152
+ let i = 0;
153
+ for (let len = keyArr.length; i < len - 1; ++i) {
154
+ if (!tempObj && !strict) break;
155
+ const key = keyArr[i];
156
+ if (key in tempObj) {
157
+ tempObj = tempObj[key];
158
+ } else {
159
+ if (strict) {
160
+ throw new Error("please transfer a valid prop path to form item!");
161
+ }
162
+ break;
163
+ }
164
+ }
165
+ // return {
166
+ // o: tempObj,
167
+ // k: keyArr[i],
168
+ // v: tempObj ? tempObj[keyArr[i]] : null,
169
+ // };
170
+ return tempObj ? tempObj[keyArr[i]] : null;
171
+ }
172
+ /** 遍历循环展示row数据 */
173
+ showValue(row: any, key: string) {
174
+ if (key) {
175
+ if (key.includes(".")) {
176
+ //存在多级的情况
177
+ //console.log("eval", key, eval(row[key]));
178
+ // const arrKey = key.split(".");
179
+ // let data = row;
180
+ // arrKey.forEach((item) => {
181
+ // if (data[item]) {
182
+ // data = data[item];
183
+ // } else {
184
+ // data = "";
185
+ // }
186
+ // });
187
+ return "";
188
+ } else {
189
+ //如果不存在多级数据
190
+ return row[key];
191
+ }
192
+ } else {
193
+ return "";
194
+ }
195
+ }
146
196
  /** 监听 */
147
197
  @Watch("pageInfo")
148
198
  setPageInfo(val?: PageInfoType) {
@@ -4,7 +4,7 @@
4
4
  * @Author: hutao
5
5
  * @Date: 2021-12-08 11:30:56
6
6
  * @LastEditors: hutao
7
- * @LastEditTime: 2021-12-09 16:20:43
7
+ * @LastEditTime: 2021-12-09 18:04:54
8
8
  -->
9
9
 
10
10
  <!--
@@ -44,7 +44,9 @@ interface State {
44
44
  };
45
45
  }
46
46
 
47
- @Component
47
+ @Component({
48
+ name: "HtPagination",
49
+ })
48
50
  export default class HtPagination extends Vue {
49
51
  /** 通用样式 */
50
52
  @Prop() comStyle!: string;
@@ -4,7 +4,7 @@
4
4
  * @Author: hutao
5
5
  * @Date: 2021-10-21 10:08:41
6
6
  * @LastEditors: hutao
7
- * @LastEditTime: 2021-12-09 17:23:46
7
+ * @LastEditTime: 2021-12-09 17:27:01
8
8
  */
9
9
 
10
10
  // 导入组件
@@ -36,6 +36,6 @@ export default {
36
36
  // 导出的对象必须具有 install,才能被 Vue.use() 方法安装
37
37
  install,
38
38
  // 以下是具体的组件列表
39
- ...components
39
+ HtSelectTable, HtPagination, HtTable
40
40
  }
41
41
 
@@ -4,7 +4,7 @@
4
4
  * @Author: hutao
5
5
  * @Date: 2021-11-15 14:41:40
6
6
  * @LastEditors: hutao
7
- * @LastEditTime: 2021-12-09 16:47:22
7
+ * @LastEditTime: 2021-12-12 09:03:38
8
8
  -->
9
9
  <template>
10
10
  <div>
@@ -45,17 +45,21 @@ export default class Index extends Vue {
45
45
  state: State = {
46
46
  loading: false,
47
47
  data: [
48
- { name: "胡涛", age: 12, sex: 0, id: 1 },
49
- { name: "胡涛", age: 12, sex: 1, id: 2 },
50
- { name: "胡涛", age: 12, sex: 1, id: 3 },
51
- { name: "胡涛", age: 12, sex: 0, id: 4 },
48
+ { name: "胡涛", age: 12, sex: 0, id: 1, test: { title: "测试" } },
49
+ { name: "胡涛", age: 12, sex: 1, id: 2, test: { title: "测试" } },
50
+ { name: "胡涛", age: 12, sex: 1, id: 3, test: { title: "测试" } },
51
+ { name: "胡涛", age: 12, sex: 0, id: 4, test: { title: "测试" } },
52
52
  ],
53
53
  columns: [
54
54
  {
55
55
  title: "姓名",
56
- key: "name",
56
+ key: "test.title",
57
57
  width: "300px",
58
58
  },
59
+ {
60
+ title: "姓额外名",
61
+ key: "name",
62
+ },
59
63
  {
60
64
  title: "age",
61
65
  key: "age",