@tripup-company/element-ui-extended 0.0.4 → 0.0.6

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.
@@ -1,67 +1,32 @@
1
1
  <template>
2
- <div v-loading="loading" class="generic-table">
3
- <slot>
4
- <el-row v-if="showTopFilter" :gutter="20">
5
- <generic-top-filter ref="genericTopFilter" />
6
- </el-row>
7
- <el-row :gutter="20">
8
- <el-col :span="18">
9
- <generic-rows />
10
- <el-row>
11
- <el-col>
12
- <generic-paginator />
13
- </el-col>
14
- </el-row>
15
- </el-col>
16
- <el-col :span="6">
17
- <generic-filter ref="genericFilter" />
18
- </el-col>
19
- </el-row>
20
- </slot>
2
+ <div>
3
+ <el-table :data="data" border @sort-change="sortChange">
4
+ <template v-for="field in fields">
5
+ <template v-if="field.callback">
6
+ <el-table-column :key="field.prop" v-slot="context" :prop="field.prop" :label="field.label" :width="field.width ? field.width : null" sortable="custom">
7
+ <el-link @click="field.callback(field.prop, context.$index, context.row)">
8
+ {{ typeof field.formatter === 'function' ? field.formatter(context.row) : context.row[field.prop] }}
9
+ </el-link>
10
+ </el-table-column>
11
+ </template>
12
+ <template v-else>
13
+ <el-table-column :formatter="typeof field.formatter === 'function' ? field.formatter : null" :key="field.prop" :prop="field.prop" :label="field.label" :width="field.width ? field.width : null" sortable="custom" />
14
+ </template>
15
+ </template>
16
+ </el-table>
21
17
  </div>
22
18
  </template>
19
+
23
20
  <script>
24
- import GenericPaginator from "./GenericPaginator";
25
- import GenericFilter from "./GenericFilter";
26
- import GenericTopFilter from "./GenericTopFilter";
27
- import GenericRows from "./GenericRows";
28
- import MetaModel from "../../models/meta-model.ts";
29
- import ListQueryService from "../../services/list-query-service.ts";
30
- import FilterConverter from "./filter-convertor.ts";
21
+
31
22
  export default {
32
23
  name: "GenericTable",
33
- components: {
34
- GenericRows,
35
- GenericFilter,
36
- GenericPaginator,
37
- GenericTopFilter,
38
- },
39
- provide() {
40
- const data = {};
41
- ["items", "fields", "filters", "loading", "meta"].forEach((key) => {
42
- Object.defineProperty(data, key, {
43
- enumerable: true,
44
- get: () => this[key],
45
- });
46
- });
47
- return {
48
- data,
49
- search: this.search,
50
- actions: {
51
- handleSizeChange: this.handleSizeChange,
52
- handleCurrentChange: this.handleCurrentChange,
53
- handleFilterChange: this.handleFilterChange,
54
- handleApplyFilter: this.handleApplyFilter,
55
- handleResetFilter: this.handleResetFilter,
56
- },
57
- };
58
- },
59
24
  props: {
60
- repository: {
25
+ data: {
61
26
  default() {
62
27
  return {};
63
28
  },
64
- type: Object,
29
+ type: Array,
65
30
  },
66
31
  title: {
67
32
  default: "",
@@ -71,111 +36,16 @@ export default {
71
36
  default: () => [],
72
37
  type: Array,
73
38
  },
74
- filters: {
75
- default: () => [],
76
- type: Array,
77
- },
78
39
  },
79
40
  data: function () {
80
- let search = {};
81
- const filterConvertor = new FilterConverter();
82
- const listQueryService = new ListQueryService(
83
- this.$route.name,
84
- this.$services.localStorage()
85
- );
86
- for (const column of this.filters) {
87
- search[column.name] = {
88
- operator: "",
89
- value: "",
90
- position: column.position ? column.position : null,
91
- };
92
- }
93
- search = Object.assign(search, listQueryService.getListQuery().search);
94
41
  return {
95
42
  loading: false,
96
- filter: {},
97
- items: [],
98
- search: search,
99
- meta: new MetaModel(),
100
- filterConvertor: filterConvertor,
101
- listQueryService: listQueryService,
102
43
  };
103
44
  },
104
- computed: {
105
- showTopFilter() {
106
- if (this.filters.filter((e) => e.position === "top").length > 0) {
107
- return true;
108
- }
109
- return false;
110
- },
111
- queryFilter() {
112
- const meta = this.listQueryService.getListQuery().meta;
113
- const query = {
114
- page: this.meta?.pagination?.current_page
115
- ? this.meta.pagination.current_page
116
- : meta.page,
117
- limit: this.meta?.pagination?.per_page
118
- ? this.meta.pagination.per_page
119
- : meta.limit,
120
- };
121
- return { ...query, ...this.filter };
122
- },
123
- },
124
- mounted() {
125
- this.filter = this.$refs.genericFilter.getFilter();
126
- this.fetch();
127
- },
128
45
  methods: {
129
- async fetch() {
130
- this.loading = true;
131
- try {
132
- const response = await this.repository.all(this.queryFilter);
133
- this.items = response.data;
134
- this.meta = response.meta;
135
- } catch (e) {
136
- this.$message.error(e.message);
137
- }
138
- this.loading = false;
139
- },
140
-
141
- handleSizeChange(val) {
142
- this.listQueryService.updateListQuery({ meta: { limit: val } });
143
- this.meta.pagination.per_page = val;
144
- this.fetch();
145
- },
146
- handleCurrentChange(val) {
147
- this.listQueryService.updateListQuery({ meta: { page: val } });
148
- this.meta.pagination.current_page = val;
149
- this.fetch();
150
- },
151
- handleFilterChange(val) {
152
- this.filter = val;
153
- this.meta.pagination.current_page = 1;
154
- this.fetch();
155
- },
156
- handleApplyFilter() {
157
- this.listQueryService.updateListQuery({ search: this.search });
158
- this.handleFilterChange(this.filterConvertor.applyFilter(this.search));
159
- },
160
- handleResetFilter() {
161
- console.log(this.search);
162
- for (const column in this.search) {
163
- if (this.search[column].position === "top") {
164
- this.search[column] = Object.assign(this.search[column], {
165
- value: "",
166
- });
167
- } else {
168
- this.search[column] = Object.assign(this.search[column], {
169
- operator: "",
170
- value: "",
171
- });
172
- }
173
- }
174
- this.listQueryService.updateListQuery({ search: this.search });
175
- this.handleFilterChange({});
176
- },
177
- },
46
+ sortChange(data) {
47
+ this.$emit('sort:change', data);
48
+ }
49
+ }
178
50
  };
179
51
  </script>
180
-
181
- <style scoped></style>
@@ -0,0 +1,15 @@
1
+ <template>
2
+ <div>
3
+ Hello world!
4
+ </div>
5
+ </template>
6
+
7
+ <script>
8
+ export default {
9
+ name: 'TestComponent',
10
+ };
11
+ </script>
12
+
13
+ <style scoped>
14
+
15
+ </style>
@@ -1,37 +0,0 @@
1
- <template>
2
- <div class="m-t-15">
3
- <el-pagination
4
- :current-page="currentPage"
5
- :total="total"
6
- :layout="'total, sizes, prev, pager, next, jumper'"
7
- @size-change="actions.handleSizeChange"
8
- @current-change="actions.handleCurrentChange"
9
- />
10
- </div>
11
- </template>
12
-
13
- <script>
14
-
15
- export default {
16
- name: 'GenericPaginator',
17
- inject: ['data', 'actions'],
18
- computed: {
19
- currentPage(){
20
- if (this.data.meta?.pagination){
21
- return this.data.meta.pagination.current_page;
22
- }
23
- return 0;
24
- },
25
- total(){
26
- if (this.data.meta?.pagination){
27
- return this.data.meta.pagination.total;
28
- }
29
- return 0;
30
- },
31
- },
32
- };
33
- </script>
34
-
35
- <style scoped>
36
-
37
- </style>
@@ -1,27 +0,0 @@
1
- <template>
2
- <div>
3
- <slot :items="data.items" :fields="data.fields">
4
- <el-table :data="data.items" border>
5
- <template v-for="field in data.fields">
6
- <template v-if="field.callback">
7
- <el-table-column :key="field.prop" v-slot="context" :prop="field.prop" :label="field.label" :width="field.width ? field.width : null">
8
- <el-link @click="field.callback(field.prop, context.$index, context.row)">
9
- {{ typeof field.formatter === 'function' ? field.formatter(context.row) : context.row[field.prop] }}
10
- </el-link>
11
- </el-table-column>
12
- </template>
13
- <template v-else>
14
- <el-table-column :formatter="typeof field.formatter === 'function' ? field.formatter : null" :key="field.prop" :prop="field.prop" :label="field.label" :width="field.width ? field.width : null" />
15
- </template>
16
- </template>
17
- </el-table>
18
- </slot>
19
- </div>
20
- </template>
21
-
22
- <script>
23
- export default {
24
- name: 'GenericRows',
25
- inject: ['data'],
26
- };
27
- </script>