vue-2024-ui 0.0.2 → 0.0.4

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/README.md CHANGED
@@ -1,29 +1,29 @@
1
- # vue-ele-ui
2
-
3
- This template should help get you started developing with Vue 3 in Vite.
4
-
5
- ## Recommended IDE Setup
6
-
7
- [VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur).
8
-
9
- ## Customize configuration
10
-
11
- See [Vite Configuration Reference](https://vitejs.dev/config/).
12
-
13
- ## Project Setup
14
-
15
- ```sh
16
- npm install
17
- ```
18
-
19
- ### Compile and Hot-Reload for Development
20
-
21
- ```sh
22
- npm run dev
23
- ```
24
-
25
- ### Compile and Minify for Production
26
-
27
- ```sh
28
- npm run build
29
- ```
1
+ # vue-ele-ui
2
+
3
+ This template should help get you started developing with Vue 3 in Vite.
4
+
5
+ ## Recommended IDE Setup
6
+
7
+ [VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur).
8
+
9
+ ## Customize configuration
10
+
11
+ See [Vite Configuration Reference](https://vitejs.dev/config/).
12
+
13
+ ## Project Setup
14
+
15
+ ```sh
16
+ npm install
17
+ ```
18
+
19
+ ### Compile and Hot-Reload for Development
20
+
21
+ ```sh
22
+ npm run dev
23
+ ```
24
+
25
+ ### Compile and Minify for Production
26
+
27
+ ```sh
28
+ npm run build
29
+ ```
package/package.json CHANGED
@@ -1,30 +1,31 @@
1
- {
2
- "name": "vue-2024-ui",
3
- "version": "0.0.2",
4
- "private": false,
5
- "type": "module",
6
- "main": "src/components/index.js",
7
- "author": {
8
- "name": "guoyuanchao",
9
- "email": "xg816620@163.com"
10
- },
11
- "files": [
12
- "src/components"
13
- ],
14
- "scripts": {
15
- "dev": "vite",
16
- "build": "vite build",
17
- "preview": "vite preview"
18
- },
19
- "dependencies": {
20
- "element-plus": "^2.8.4",
21
- "vue": "^3.4.29"
22
- },
23
- "license": "MIT",
24
- "devDependencies": {
25
- "@vitejs/plugin-vue": "^5.0.5",
26
- "@vitejs/plugin-vue-jsx": "^4.0.0",
27
- "vite": "^5.3.1",
28
- "vite-plugin-vue-devtools": "^7.3.1"
29
- }
30
- }
1
+ {
2
+ "name": "vue-2024-ui",
3
+ "version": "0.0.4",
4
+ "private": false,
5
+ "type": "module",
6
+ "main": "src/components/index.js",
7
+ "author": {
8
+ "name": "guoyuanchao",
9
+ "email": "xg816620@163.com"
10
+ },
11
+ "files": [
12
+ "src/components"
13
+ ],
14
+ "scripts": {
15
+ "i": "pnpm i",
16
+ "dev": "vite",
17
+ "build": "vite build",
18
+ "preview": "vite preview"
19
+ },
20
+ "dependencies": {
21
+ "element-plus": "^2.8.4",
22
+ "vue": "^3.4.29"
23
+ },
24
+ "license": "MIT",
25
+ "devDependencies": {
26
+ "@vitejs/plugin-vue": "^5.0.5",
27
+ "@vitejs/plugin-vue-jsx": "^4.0.0",
28
+ "vite": "^5.3.1",
29
+ "vite-plugin-vue-devtools": "^7.3.1"
30
+ }
31
+ }
@@ -162,7 +162,6 @@ const selectRemoteMethod = (query) => {
162
162
  onMounted(() => {
163
163
  if (itemInfo["remote-method"]) {
164
164
  selectModel['remote-method'] = selectRemoteMethod;
165
-
166
165
  }
167
166
  })
168
167
  </script>
@@ -116,7 +116,7 @@ const submitForm = async (model) => {
116
116
  // 重置表单
117
117
  const resetForm = () => {
118
118
  if (!gform.value) return
119
- const isreset = true;
119
+ let isreset = true;
120
120
  emits("reset", (flag) => {
121
121
  isreset = flag;
122
122
  });
@@ -224,7 +224,6 @@ const load = () => {
224
224
  model.value.form.columns = 1;
225
225
  }
226
226
  const width = getComputedStyle(document.querySelector(".g-form-container")).width;
227
- console.log(width);
228
227
  if (width === "600px") {
229
228
  columnsWidth.value = 300;
230
229
  model.value.form.style.width = columns.value * 300 + 'px';
@@ -9,6 +9,34 @@
9
9
  <div v-html="formatterExtends(value, column.formatter(row, column, row[key], $index))"></div>
10
10
  </slot>
11
11
  </template>
12
+ <template #default="{ row, column, $index }" v-if="value.type == 'control'">
13
+ <div class="control" v-bind="value">
14
+ <slot name="control">
15
+ <slot name="control-left" :row :column :$index> </slot>
16
+ <slot name="control-read" :row :column :$index
17
+ v-if="model.control.read.auth(row, column, $index)">
18
+ <el-button v-bind="model.control.read"
19
+ @click="model.control.read.read(row, column, $index)">{{ model.control.read.label
20
+ }}</el-button>
21
+ </slot>
22
+ <slot name="control-edit-left" :row :column :$index> </slot>
23
+ <slot name="control-edit" :row :column :$index
24
+ v-if="model.control.edit.auth(row, column, $index)">
25
+ <el-button v-bind="model.control.edit"
26
+ @click="model.control.edit.edit(row, column, $index)">{{ model.control.edit.label
27
+ }}</el-button>
28
+ </slot>
29
+ <slot name="control-edit-right" :row :column :$index> </slot>
30
+ <slot name="control-delete" :row :column :$index
31
+ v-if="model.control.delete.auth(row, column, $index)">
32
+ <el-button v-bind="model.control.delete"
33
+ @click="model.control.delete.delete(row, column, $index)">{{
34
+ model.control.delete.label }}</el-button>
35
+ </slot>
36
+ <slot name="control-right" :row :column :$index> </slot>
37
+ </slot>
38
+ </div>
39
+ </template>
12
40
  <template #header="{ column, $index }">
13
41
  <slot :name="`${key}-header`" :column :$index></slot>
14
42
  </template>
@@ -32,17 +60,21 @@
32
60
  </slot>
33
61
  </template>
34
62
 
35
- <script setup>
63
+ <script setup >
36
64
  import dayjs from 'dayjs';
37
- import { computed, onMounted, reactive, watchEffect } from 'vue';
65
+ import ElementPlus from 'element-plus'
66
+ import { ElMessageBox } from 'element-plus';
67
+ import { computed, onMounted, reactive, watchEffect, h, createApp, ref } from 'vue';
68
+ import { ElDialog } from 'element-plus';
69
+ import gyc from "./index"
70
+ import GForm from './g-form.vue';
38
71
 
39
72
  defineOptions({
40
73
  name: "g-table",
41
74
  inheritAttrs: false
42
75
  })
43
76
 
44
- const emits = defineEmits(['load']);
45
-
77
+ const emits = defineEmits(['load', 'read', "edit", "delete"]);
46
78
  const model = defineModel({ required: true });
47
79
 
48
80
  //table default attrs
@@ -54,7 +86,6 @@ model.value.table = {
54
86
  fit: false,
55
87
  type: "hidden",
56
88
  height: "calc(100vh - 55px)",
57
-
58
89
  ...model.value.table,
59
90
  load: () => {
60
91
  let { currentPage, pageSize } = model.value.table.page;
@@ -66,7 +97,7 @@ model.value.table = {
66
97
  page: {
67
98
  background: true,
68
99
  total: 0,
69
- pageSize: 10,
100
+ pageSize: 20,
70
101
  currentPage: 1,
71
102
  pageSizes: [5, 10, 20, 30, 40, 50],
72
103
  layout: 'total, sizes, prev, pager, next, jumper',
@@ -77,11 +108,68 @@ model.value.table = {
77
108
  padding: "10px",
78
109
  ...model.value.table?.page?.style
79
110
  },
80
- onChange: (a, b) => {
81
- console.log(a, b);
82
- }
83
111
  }
84
112
  }
113
+ model.value.control = {
114
+ type: model.value?.control ? "control" : 'hidden', label: '操作', width: 250, fixed: 'right', ...model.value?.control,
115
+ style: { ...model.value?.control?.style },
116
+ read: {
117
+ text: true, label: '查看', type: 'success',
118
+ auth: (row, column, $index) => {
119
+ return false;
120
+ },
121
+ read: (row, column, $index) => {
122
+ emits("read", row, column, $index);
123
+ model.value.form.disabled = true;
124
+ openModal({
125
+ title: '查看',
126
+ slots: {
127
+ // 自定义插槽内容
128
+ default: () => h(GForm, { modelValue: model.value }),
129
+ },
130
+ });
131
+ }, ...model.value?.control?.read
132
+ },
133
+ edit: {
134
+ text: true, label: '编辑', type: 'primary',
135
+ auth: (row, column, $index) => {
136
+ return true;
137
+ },
138
+ edit: (row, column, $index) => {
139
+ model.value.form.disabled = undefined;
140
+ emits("edit", row, column, $index);
141
+ openModal({
142
+ title: '编辑',
143
+ slots: {
144
+ // 自定义插槽内容
145
+ default: () => h(GForm, { modelValue: model.value }),
146
+ },
147
+ });
148
+
149
+ }, ...model.value?.control?.edit
150
+ },
151
+ delete: {
152
+ text: true, label: '删除', type: 'danger',
153
+ auth: (row, column, $index) => {
154
+ return true;
155
+ },
156
+ delete: (row, column, $index) => {
157
+ ElMessageBox.confirm('此操作将永久删除该文件, 是否继续?', '提示', {
158
+ confirmButtonText: '确定',
159
+ cancelButtonText: '取消',
160
+ type: 'warning'
161
+ }).then(() => {
162
+ emits("delete", { row, column, $index }, (res) => {
163
+ if (res) {
164
+ model.value.table.data.splice($index, 1);
165
+ console.log(model.value.table.data)
166
+ }
167
+ })
168
+ }).catch(() => { });
169
+
170
+ }, ...model.value?.control?.delete
171
+ },
172
+ };
85
173
 
86
174
  //table column default attrs
87
175
  const itemValue = reactive({
@@ -90,6 +178,40 @@ const itemValue = reactive({
90
178
  }
91
179
  });
92
180
 
181
+ // 用 createApp 方法封装打开模态窗的方法
182
+ const openModal = (props = {}) => {
183
+ const app = createApp({
184
+ setup() {
185
+ const visible = ref(true);
186
+ const closeModal = () => {
187
+ visible.value = false;
188
+ app.unmount(); // 关闭对话框时卸载组件
189
+ };
190
+ return () => h(ElDialog, {
191
+ modelValue: visible.value,
192
+ 'onUpdate:modelValue': closeModal,
193
+ width: 635,
194
+ draggable: true,
195
+ "append-to-body": true,
196
+ ...props
197
+ },
198
+ () => [
199
+ props.slots.header ? h('div', { slot: 'header' }, props.slots.header()) : null,
200
+ // 传递名为 'default' 的插槽
201
+ props.slots.default ? h(props.slots.default()) : null,
202
+ // 传递名为 'header' 的插槽
203
+ // 传递名为 'footer' 的插槽
204
+ props.slots.footer ? h('div', { slot: 'footer' }, props.slots.footer()) : null,
205
+ // 可以继续添加其他插槽...
206
+ ]
207
+ );
208
+ }
209
+ });
210
+ const el = document.createElement('div');
211
+ app.use(ElementPlus).use(gyc).mount(el);
212
+ document.body.appendChild(el);
213
+ };
214
+
93
215
  //扩展formatter方法
94
216
  const formatterExtends = (item, str) => {
95
217
  let trueValue = str;
@@ -128,6 +250,7 @@ const formatterExtends = (item, str) => {
128
250
  }
129
251
  return trueValue
130
252
  }
253
+
131
254
  onMounted(() => {
132
255
 
133
256
  });
@@ -137,8 +260,12 @@ watchEffect(() => {
137
260
  });
138
261
 
139
262
  //表单项
140
- const tableColumns = computed(() => Object.fromEntries(Object.entries(model.value).filter(a => a[1].type != "hidden").filter(a => a[1].visible !== false).map(key => [key[0], key[1]])));
141
- //const formInfo = computed(() => Object.fromEntries(Object.entries(model.value).filter(a => a[1].type != "hidden").map(key => [key[0], key[1].value])));
263
+ const tableColumns = computed(() => Object.fromEntries(
264
+ Object.entries(model.value)
265
+ .filter(a => a[1].type != "hidden")
266
+ .filter(a => a[1].visible !== false)
267
+ .map(key => [key[0], key[1]]))
268
+ );
142
269
  </script>
143
270
 
144
271
  <style lang="scss" scoped></style>