vue-2024-ui 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.
package/README.md CHANGED
@@ -1,29 +1,48 @@
1
- # vue-ele-ui
1
+ # vue-2024-ui
2
2
 
3
- This template should help get you started developing with Vue 3 in Vite.
3
+ vue + element-plus
4
4
 
5
- ## Recommended IDE Setup
5
+ ```
6
+ npm i vue-2024-ui
7
+ ```
6
8
 
7
- [VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur).
9
+ # API 说明
10
+ ### 所有属性和方法都在element-plus 基础上扩展,只显示增加的属性和方法,安装前必须安装element-plus,其他原有属性和方法请查询 [官方文档](https://element-plus.org/zh-CN/component/overview.html)
8
11
 
9
- ## Customize configuration
12
+ # form 表单增加的属性
10
13
 
11
- See [Vite Configuration Reference](https://vitejs.dev/config/).
14
+ | 属性 | 说明 | 类型 | 默认值 |
15
+ | --------- | ------------------------------------------------------------------- | ------ | -------------------------------------------------------------------------------------------- |
16
+ | columns | 表单列数 | number | 2 |
17
+ | footer | 控制表单底部按钮是否显示和样式设置,hidden默认是false,style控制样式 | object | ```{hidden: false, style:{ display:"flex","align-items":"center",justifyContent:"center"}``` |
18
+ | submit | 表单提交按钮,增加了submitText,hidden 属性和submit方法 | object | ``` {type: "primary",submitText: "提交",hidden: false,submit: async (model) => {...}, } ``` |
19
+ | reset | 表单重置按钮,增加了restText,hidden 属性和reset方法 | object | ``` {type: "primary",resetText: "重置",hidden: false,reset: () => {...}, } ``` |
20
+ | formItems | 通过style属性设置所有items的样式 | object | ``` style:{width:100%} ``` |
12
21
 
13
- ## Project Setup
14
22
 
15
- ```sh
16
- npm install
17
- ```
23
+ # form 增加的事件
18
24
 
19
- ### Compile and Hot-Reload for Development
25
+ | 事件名 | 说明 | 类型 | 参数 |
26
+ | ------ | ------------ | -------- | -------------------------------------------------------------------------------------- |
27
+ | submit | 表单提交事件 | function | formData:表单要提交的数据 |
28
+ | reset | 表单重置事件 | function | callback(isCustReset=false) 默认已处理了重置事件,如要重写事件则回调时传入true后再处理 |
20
29
 
21
- ```sh
22
- npm run dev
23
- ```
24
30
 
25
- ### Compile and Minify for Production
26
31
 
27
- ```sh
28
- npm run build
29
- ```
32
+ # form 重写 slots 增加的插槽
33
+
34
+ | 插槽名 | 说明 |
35
+ | ------------ | ---------------------- |
36
+ | footer | 重写表单footer功能按钮 |
37
+ | footer-left | 表单左边增加按钮 |
38
+ | footer-right | 表单右边增加按钮 |
39
+
40
+ # formItem 重写 slots
41
+
42
+ | 插槽名 | 说明 |
43
+ | --------------------- | -------------------------------- |
44
+ | item.key | 重写表单项item |
45
+ | item.key-label | 重写表单项标题 |
46
+ | item.key-ctrl | 重写表单控件 |
47
+ | item.key-ctrl-options | 重写表单控件有options的字项items |
48
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-2024-ui",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "src/components/index.js",
@@ -15,15 +15,15 @@
15
15
  <slot :name="`${key}-label`" :data :item :model>{{ item.label }}</slot>
16
16
  </template>
17
17
  </el-form-item>
18
- <el-form-item style="width: 100%;">
18
+ <el-form-item style="width: 100%;" v-if="!model.form.footer.hidden">
19
19
  <slot name="footer">
20
- <div style="display: flex; width:100%;align-items: center;" :style="model.form.footer">
20
+ <div :style="model.form.footer.style">
21
21
  <slot name="footer-left"></slot>
22
- <el-button @click="submitForm(model)" v-bind="model.form.submit"
22
+ <el-button @click="model.form.submit.submit(model)" v-bind="model.form.submit"
23
23
  v-if="!model.form.submit.hidden">
24
24
  {{ model.form.submit.submitText }}
25
25
  </el-button>
26
- <el-button @click="resetForm(ruleFormRef)" v-bind="model.form.reset"
26
+ <el-button @click="model.form.reset.reset(model)" v-bind="model.form.reset"
27
27
  v-if="!model.form.reset.hidden">{{
28
28
  model.form.reset.resetText
29
29
  }}</el-button>
@@ -70,8 +70,11 @@ model.value.form = {
70
70
  },
71
71
  // 表单底部属性
72
72
  footer: {
73
- justifyContent: "center",
74
- ...model.value.form?.footer
73
+ hidden: false,
74
+ ...model.value.form?.footer,
75
+ style: {
76
+ display: "flex", width: "100%", "align-items": "center", justifyContent: "center", margin: "5px", ...model.value.form?.footer?.style
77
+ },
75
78
  },
76
79
  //表单提交按钮属性
77
80
  submit: {
@@ -80,6 +83,16 @@ model.value.form = {
80
83
  submitText: "提交",
81
84
  plain: true,
82
85
  hidden: false,
86
+ submit: async (model) => {
87
+ if (!gform.value) return
88
+ await gform.value.validate((valid, fields) => {
89
+ if (valid) {
90
+ emits("submit", formInfo.value, model);
91
+ } else {
92
+ console.log('error submit!', fields);
93
+ }
94
+ })
95
+ },
83
96
  ...model.value.form?.submit
84
97
  },
85
98
  //表单重置按钮属性
@@ -88,48 +101,33 @@ model.value.form = {
88
101
  resetText: "重置",
89
102
  hidden: false,
90
103
  plain: true,
104
+ reset: () => {
105
+ if (!gform.value) return
106
+ let isreset = true;
107
+ emits("reset", (flag) => {
108
+ isreset = flag;
109
+ });
110
+ if (isreset) {
111
+ gform.value.resetFields();
112
+ }
113
+ },
91
114
  ...model.value.form?.reset
92
115
  },
116
+ dialog: {
117
+ width: 635,
118
+ ...model.value.form?.dialog
119
+ }
93
120
  };
94
121
  //合并表单项默认属性
95
122
  model.value.formItems = {
96
123
  type: "hidden",
97
- ...model.value.formItems,
98
124
  style: {
99
125
  width: "100%",
100
126
  ...model.value.formItems?.style
101
- }
127
+ },
128
+ ...model.value.formItems,
102
129
  };
103
130
 
104
- // 提交表单
105
- const submitForm = async (model) => {
106
- if (!gform.value) return
107
- await gform.value.validate((valid, fields) => {
108
- if (valid) {
109
- emits("submit", formInfo.value, model);
110
- } else {
111
- console.log('error submit!', fields);
112
- }
113
- })
114
- }
115
-
116
- // 重置表单
117
- const resetForm = () => {
118
- if (!gform.value) return
119
- let isreset = true;
120
- emits("reset", (flag) => {
121
- isreset = flag;
122
- });
123
- if (isreset) {
124
- gform.value.resetFields();
125
- }
126
- }
127
-
128
- // 定义对外暴露的函数
129
- defineExpose({
130
- submit: submitForm, reset: resetForm
131
- })
132
-
133
131
  //获取表单项验证规则
134
132
  const getItemRulesByItem = (item) => {
135
133
  // 组装验证规则
@@ -223,14 +221,14 @@ const load = () => {
223
221
  if (!model.value.form.inline) {
224
222
  model.value.form.columns = 1;
225
223
  }
226
- const width = getComputedStyle(document.querySelector(".g-form-container")).width;
227
- if (width === "600px") {
228
- columnsWidth.value = 300;
229
- model.value.form.style.width = columns.value * 300 + 'px';
230
- } else {
231
- columnsWidth.value = removePx(width) / model.value.form.columns;
232
- model.value.form.style.width = columns.value * columnsWidth.value + 'px';
224
+ if (model.value.form.style.width) {
225
+ columnsWidth.value = removePx(model.value.form.style.width) / model.value.form.columns;
233
226
  }
227
+ else {
228
+ model.value.form.style.width = "600px";
229
+ }
230
+ model.value.form.dialog.width = +model.value?.form?.style?.width.replace("px", "")+35+"px";
231
+ console.log(model.value.form.dialog.width);
234
232
  for (const [key, value] of Object.entries(items.value)) {
235
233
  model.value[key].formItem = { ...model.value[key].formItem, ...value.formItem }
236
234
  model.value[key].formItem.style = { ...model.value[key].formItem.style, ...value.formItem.style };
@@ -251,15 +249,13 @@ watch(() => model.value.form.columns, () => load());
251
249
  watch(() => model.value.form.inline, () => load());
252
250
 
253
251
  const removePx = (el) => parseFloat(el.replace("px", ""));
254
-
255
252
  //表单项
256
- const items = computed(() => Object.fromEntries(Object.entries(model.value).filter(a => a[1].type != "hidden").filter(a => (a[1].edit !== false)).map(key => [key[0], key[1]])));
253
+ const items = computed(() => Object.fromEntries(Object.entries(model.value).filter(a => a[1].type != "hidden")
254
+ .filter(a => (a[1].edit !== false))
255
+ .filter(a => (a[1].type !== "control"))
256
+ .map(key => [key[0], key[1]])));
257
257
  //表单提交对象
258
258
  const formInfo = computed(() => Object.fromEntries(Object.entries(model.value).filter(a => a[1].type != "hidden").map(key => [key[0], key[1].value])));
259
259
  //表单列数
260
260
  const columns = computed(() => model.value.form.columns);
261
- //表单列的宽度减去右边距
262
- const formItemsWidth = computed(() => columnsWidth.value - marginRight.value);
263
- //表单宽度
264
- const formWidth = computed(() => columns.value * columnsWidth.value);
265
261
  </script>
@@ -13,17 +13,19 @@
13
13
  <div class="control" v-bind="value">
14
14
  <slot name="control">
15
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
16
+ <slot name="control-view" :row :column :$index
17
+ v-if="model.control.view.auth(row, column, $index)">
18
+ <el-button v-bind="model.control.view"
19
+ @click="model.control.view.view(row, column, $index, model)">{{
20
+ model.control.view.label
20
21
  }}</el-button>
21
22
  </slot>
22
23
  <slot name="control-edit-left" :row :column :$index> </slot>
23
24
  <slot name="control-edit" :row :column :$index
24
25
  v-if="model.control.edit.auth(row, column, $index)">
25
26
  <el-button v-bind="model.control.edit"
26
- @click="model.control.edit.edit(row, column, $index)">{{ model.control.edit.label
27
+ @click="model.control.edit.edit(row, column, $index, model)">{{
28
+ model.control.edit.label
27
29
  }}</el-button>
28
30
  </slot>
29
31
  <slot name="control-edit-right" :row :column :$index> </slot>
@@ -60,13 +62,13 @@
60
62
  </slot>
61
63
  </template>
62
64
 
63
- <script setup >
65
+ <script setup>
64
66
  import dayjs from 'dayjs';
65
67
  import ElementPlus from 'element-plus'
66
68
  import { ElMessageBox } from 'element-plus';
67
- import { computed, onMounted, reactive, watchEffect, h, createApp, ref } from 'vue';
69
+ import { computed, onMounted, reactive, watchEffect, watch, h, createApp, ref } from 'vue';
68
70
  import { ElDialog } from 'element-plus';
69
- import gyc from "./index"
71
+ //import gyc from "./index"
70
72
  import GForm from './g-form.vue';
71
73
 
72
74
  defineOptions({
@@ -74,7 +76,7 @@ defineOptions({
74
76
  inheritAttrs: false
75
77
  })
76
78
 
77
- const emits = defineEmits(['load', 'read', "edit", "delete"]);
79
+ const emits = defineEmits(['load', 'view', "edit", "delete"]);
78
80
  const model = defineModel({ required: true });
79
81
 
80
82
  //table default attrs
@@ -111,38 +113,42 @@ model.value.table = {
111
113
  }
112
114
  }
113
115
  model.value.control = {
114
- type: model.value?.control ? "control" : 'hidden', label: '操作', width: 250, fixed: 'right', ...model.value?.control,
116
+ type: model.value?.control ? "control" : 'hidden', label: '操作', edit: false, width: 250, fixed: 'right', ...model.value?.control,
115
117
  style: { ...model.value?.control?.style },
116
- read: {
117
- text: true, label: '查看', type: 'success',
118
+ view: {
119
+ label: '查看', text: true, type: 'success',
118
120
  auth: (row, column, $index) => {
119
121
  return false;
120
122
  },
121
- read: (row, column, $index) => {
122
- emits("read", row, column, $index);
123
+ view: (row, column, $index, m) => {
123
124
  model.value.form.disabled = true;
125
+ emits("view", row, column, $index, m);
124
126
  openModal({
125
127
  title: '查看',
128
+ ...model.value.form.dialog,
126
129
  slots: {
127
130
  // 自定义插槽内容
128
131
  default: () => h(GForm, { modelValue: model.value }),
132
+ ...model.value?.form?.dialog?.slots
129
133
  },
130
134
  });
131
- }, ...model.value?.control?.read
135
+ }, ...model.value?.control?.view
132
136
  },
133
137
  edit: {
134
- text: true, label: '编辑', type: 'primary',
138
+ label: '编辑', text: true, type: 'primary',
135
139
  auth: (row, column, $index) => {
136
140
  return true;
137
141
  },
138
- edit: (row, column, $index) => {
142
+ edit: (row, column, $index, m) => {
139
143
  model.value.form.disabled = undefined;
140
- emits("edit", row, column, $index);
144
+ emits("edit", row, column, $index, m);
141
145
  openModal({
142
146
  title: '编辑',
147
+ ...model.value.form.dialog,
143
148
  slots: {
144
149
  // 自定义插槽内容
145
150
  default: () => h(GForm, { modelValue: model.value }),
151
+ ...model.value?.form?.dialog?.slots
146
152
  },
147
153
  });
148
154
 
@@ -180,26 +186,28 @@ const itemValue = reactive({
180
186
 
181
187
  // 用 createApp 方法封装打开模态窗的方法
182
188
  const openModal = (props = {}) => {
189
+ const el = document.createElement('div');
183
190
  const app = createApp({
184
191
  setup() {
185
192
  const visible = ref(true);
186
193
  const closeModal = () => {
187
194
  visible.value = false;
188
195
  app.unmount(); // 关闭对话框时卸载组件
196
+ delete el.remove(); // 关闭对话框时删除元素
189
197
  };
190
198
  return () => h(ElDialog, {
191
199
  modelValue: visible.value,
192
200
  'onUpdate:modelValue': closeModal,
193
- width: 635,
194
201
  draggable: true,
195
202
  "append-to-body": true,
203
+ "v-if": visible.value,
204
+ width:model.value.form.dialog.width,
196
205
  ...props
197
206
  },
198
207
  () => [
199
208
  props.slots.header ? h('div', { slot: 'header' }, props.slots.header()) : null,
200
209
  // 传递名为 'default' 的插槽
201
210
  props.slots.default ? h(props.slots.default()) : null,
202
- // 传递名为 'header' 的插槽
203
211
  // 传递名为 'footer' 的插槽
204
212
  props.slots.footer ? h('div', { slot: 'footer' }, props.slots.footer()) : null,
205
213
  // 可以继续添加其他插槽...
@@ -207,8 +215,7 @@ const openModal = (props = {}) => {
207
215
  );
208
216
  }
209
217
  });
210
- const el = document.createElement('div');
211
- app.use(ElementPlus).use(gyc).mount(el);
218
+ app.use(ElementPlus).mount(el);
212
219
  document.body.appendChild(el);
213
220
  };
214
221