vue-2024-ui 0.0.2 → 0.0.3

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.3",
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,20 @@
32
60
  </slot>
33
61
  </template>
34
62
 
35
- <script setup>
63
+ <script setup lang="jsx">
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"
38
70
 
39
71
  defineOptions({
40
72
  name: "g-table",
41
73
  inheritAttrs: false
42
74
  })
43
75
 
44
- const emits = defineEmits(['load']);
45
-
76
+ const emits = defineEmits(['load', 'read', "edit", "delete"]);
46
77
  const model = defineModel({ required: true });
47
78
 
48
79
  //table default attrs
@@ -54,7 +85,6 @@ model.value.table = {
54
85
  fit: false,
55
86
  type: "hidden",
56
87
  height: "calc(100vh - 55px)",
57
-
58
88
  ...model.value.table,
59
89
  load: () => {
60
90
  let { currentPage, pageSize } = model.value.table.page;
@@ -66,7 +96,7 @@ model.value.table = {
66
96
  page: {
67
97
  background: true,
68
98
  total: 0,
69
- pageSize: 10,
99
+ pageSize: 20,
70
100
  currentPage: 1,
71
101
  pageSizes: [5, 10, 20, 30, 40, 50],
72
102
  layout: 'total, sizes, prev, pager, next, jumper',
@@ -77,11 +107,68 @@ model.value.table = {
77
107
  padding: "10px",
78
108
  ...model.value.table?.page?.style
79
109
  },
80
- onChange: (a, b) => {
81
- console.log(a, b);
82
- }
83
110
  }
84
111
  }
112
+ model.value.control = {
113
+ type: model.value?.control ? "control" : 'hidden', label: '操作', width: 250, fixed: 'right', ...model.value?.control,
114
+ style: { ...model.value?.control?.style },
115
+ read: {
116
+ text: true, label: '查看', type: 'success',
117
+ auth: (row, column, $index) => {
118
+ return false;
119
+ },
120
+ read: (row, column, $index) => {
121
+ emits("read", row, column, $index);
122
+ model.value.form.disabled=true;
123
+ openModal({
124
+ title: '查看',
125
+ slots: {
126
+ // 自定义插槽内容
127
+ default: () => <g-form v-model={model.value}></g-form>,
128
+ },
129
+ });
130
+ }, ...model.value?.control?.read
131
+ },
132
+ edit: {
133
+ text: true, label: '编辑', type: 'primary',
134
+ auth: (row, column, $index) => {
135
+ return true;
136
+ },
137
+ edit: (row, column, $index) => {
138
+ model.value.form.disabled=undefined;
139
+ emits("edit", row, column, $index);
140
+ openModal({
141
+ title: '编辑',
142
+ slots: {
143
+ // 自定义插槽内容
144
+ default: () => <g-form v-model={model.value}></g-form>,
145
+ },
146
+ });
147
+
148
+ }, ...model.value?.control?.edit
149
+ },
150
+ delete: {
151
+ text: true, label: '删除', type: 'danger',
152
+ auth: (row, column, $index) => {
153
+ return true;
154
+ },
155
+ delete: (row, column, $index) => {
156
+ ElMessageBox.confirm('此操作将永久删除该文件, 是否继续?', '提示', {
157
+ confirmButtonText: '确定',
158
+ cancelButtonText: '取消',
159
+ type: 'warning'
160
+ }).then(() => {
161
+ emits("delete", { row, column, $index }, (res) => {
162
+ if (res) {
163
+ model.value.table.data.splice($index, 1);
164
+ console.log(model.value.table.data)
165
+ }
166
+ })
167
+ }).catch(() => { });
168
+
169
+ }, ...model.value?.control?.delete
170
+ },
171
+ };
85
172
 
86
173
  //table column default attrs
87
174
  const itemValue = reactive({
@@ -90,6 +177,40 @@ const itemValue = reactive({
90
177
  }
91
178
  });
92
179
 
180
+ // 用 createApp 方法封装打开模态窗的方法
181
+ const openModal = (props = {}) => {
182
+ const app = createApp({
183
+ setup() {
184
+ const visible = ref(true);
185
+ const closeModal = () => {
186
+ visible.value = false;
187
+ app.unmount(); // 关闭对话框时卸载组件
188
+ };
189
+ return () => h(ElDialog, {
190
+ modelValue: visible.value,
191
+ 'onUpdate:modelValue': closeModal,
192
+ width: 635,
193
+ draggable: true,
194
+ "append-to-body":true,
195
+ ...props
196
+ },
197
+ () => [
198
+ props.slots.header ? h('div', { slot: 'header' }, props.slots.header()) : null,
199
+ // 传递名为 'default' 的插槽
200
+ props.slots.default ? h(props.slots.default()) : null,
201
+ // 传递名为 'header' 的插槽
202
+ // 传递名为 'footer' 的插槽
203
+ props.slots.footer ? h('div', { slot: 'footer' }, props.slots.footer()) : null,
204
+ // 可以继续添加其他插槽...
205
+ ]
206
+ );
207
+ }
208
+ });
209
+ const el = document.createElement('div');
210
+ app.use(ElementPlus).use(gyc).mount(el);
211
+ document.body.appendChild(el);
212
+ };
213
+
93
214
  //扩展formatter方法
94
215
  const formatterExtends = (item, str) => {
95
216
  let trueValue = str;
@@ -128,6 +249,7 @@ const formatterExtends = (item, str) => {
128
249
  }
129
250
  return trueValue
130
251
  }
252
+
131
253
  onMounted(() => {
132
254
 
133
255
  });
@@ -137,8 +259,12 @@ watchEffect(() => {
137
259
  });
138
260
 
139
261
  //表单项
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])));
262
+ const tableColumns = computed(() => Object.fromEntries(
263
+ Object.entries(model.value)
264
+ .filter(a => a[1].type != "hidden")
265
+ .filter(a => a[1].visible !== false)
266
+ .map(key => [key[0], key[1]]))
267
+ );
142
268
  </script>
143
269
 
144
270
  <style lang="scss" scoped></style>