Skip to content

Commit bc551df

Browse files
committed
Form Item 添加vif属性
Form 添加表单验证回调事件
1 parent 1c6c9bf commit bc551df

File tree

13 files changed

+40246
-80
lines changed

13 files changed

+40246
-80
lines changed

docs/form.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,23 @@ $form->footerComponent(Divider::make("详细信息"));
212212
$form->editing(function (Form $form) {});
213213
$form->submitted(function (Form $form) {});
214214
$form->submitted(function (Form $form) {});
215-
$form->saving(function (Form $form) {});
215+
$form->saving(function (Form $form) {
216+
217+
//返回错误信息
218+
return \Admin::responseError("xxxx");
219+
});
216220
$form->saved(function (Form $form) {});
217221
$form->deleting(function (Form $form) {});
218222
$form->deleted(function (Form $form) {});
219223

224+
//表单验证时回调,用于处理复杂的表单验证
225+
$form->validating(function (Form $form, $validator) {
226+
//-------例如
227+
$validator->sometimes('end_time', 'email', function ($input) {
228+
return true;
229+
});
230+
});
231+
220232
//表单要编辑的数据查询并处理后,可用于对不存在的关联模型字段提供数据
221233
$form->editQuery(function (Form $form,$data) {
222234

public/app.js

Lines changed: 40117 additions & 1 deletion
Large diffs are not rendered by default.

public/mix-manifest.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"/app.js": "/app.js?id=b0257459c04305121b88",
3-
"/manifest.js": "/manifest.js?id=3c768977c2574a34506e",
4-
"/vendor.js": "/vendor.js?id=5a30bc9bc2e005aa1c33"
2+
"/app.js": "/app.js?id=23a4859c644d4b2b623b",
3+
"/manifest.js": "/manifest.js?id=d9708e48a6c10ccee4bb",
4+
"/vendor.js": "/vendor.js?id=f4679ac178c0e413cb28"
55
}

resources/js/components/form/BaseForm.vue

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@
2222
:disabled="attrs.attrs.disabled"
2323
>
2424
<template v-for="(item, index) in attrs.formItems">
25-
<div :key="index">
25+
<ItemIf
26+
:key="index"
27+
:form_item="item"
28+
:form_items="attrs.formItems"
29+
:form_data="formData"
30+
>
2631
<component
2732
v-if="item.topComponent"
2833
:is="item.topComponent.componentName"
@@ -75,7 +80,7 @@
7580
:is="item.footerComponent.componentName"
7681
:attrs="item.footerComponent"
7782
/>
78-
</div>
83+
</ItemIf>
7984
</template>
8085
<div class="form-bottom-actions">
8186
<div></div>
@@ -98,9 +103,11 @@
98103
</template>
99104
<script>
100105
import ItemDiaplsy from "./ItemDiaplsy";
106+
import ItemIf from "./ItemIf";
101107
export default {
102108
components: {
103-
ItemDiaplsy
109+
ItemDiaplsy,
110+
ItemIf
104111
},
105112
props: {
106113
attrs: Object
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<template>
2+
<div v-if="ifShow">
3+
<slot></slot>
4+
</div>
5+
</template>
6+
<script>
7+
export default {
8+
props: {
9+
form_item: Object,
10+
form_items: Array,
11+
form_data: Object
12+
},
13+
computed: {
14+
ifShow() {
15+
let key = this.form_item.vif.key;
16+
let value = this.form_item.vif.value;
17+
18+
if (key) {
19+
let cValue = window._.get(this.form_data, key);
20+
if (cValue == value) {
21+
return true;
22+
} else {
23+
return false;
24+
}
25+
}
26+
27+
return true;
28+
}
29+
}
30+
};
31+
</script>

resources/js/components/grid/Table.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
:rows="selectionRows"
1111
v-if="attrs.selection"
1212
/>
13-
<div class="search-view mr-10">
13+
<div class="search-view mr-10" v-if="attrs.quickSearch">
1414
<el-input
1515
v-model="quickSearch"
1616
:placeholder="attrs.quickSearch.placeholder"
1717
:clearable="true"
1818
@clear="getData"
1919
@keyup.enter.native="getData"
20-
v-if="attrs.quickSearch"
20+
2121
>
2222
<el-button @click="getData" :loading="loading" slot="append"
2323
>搜索</el-button

resources/js/components/layout/Column.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<el-col :span="attrs.width">
33
<component
4-
v-for="(content,index) in attrs.contents"
4+
v-for="(content, index) in attrs.contents"
55
:key="index"
66
:is="content.componentName"
77
:attrs="content"
@@ -17,5 +17,4 @@ export default {
1717
};
1818
</script>
1919

20-
<style>
21-
</style>
20+
<style></style>

resources/js/components/widgets/RadioGroup.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ export default {
3232
vm: this._.clone(this.value)
3333
};
3434
},
35+
watch: {
36+
value(value) {
37+
this.vm = value;
38+
}
39+
},
3540
model: {
3641
prop: "value",
3742
event: "change"

resources/js/components/widgets/TimePicker.vue

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@
5454
:name="attrs.name"
5555
:prefix-icon="attrs.prefixIcon"
5656
:clear-icon="attrs.clearIcon"
57-
:start="attrs.start"
58-
:end="attrs.end"
59-
:step="attrs.step"
60-
:minTime="attrs.minTime"
61-
:maxTime="attrs.maxTime"
6257
@change="onChange"
6358
></el-time-select>
6459
</template>

src/Components/TimePicker.php

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ class TimePicker extends Component
3131
protected $format = "HH:mm:ss";
3232
protected $type = "select";
3333

34-
protected $start = "09:00";
35-
protected $end = "18:00";
36-
protected $step = "00:30";
37-
protected $minTime = "00:00";
38-
protected $maxTime;
3934

4035
static public function make($value = '', $type = "select")
4136
{
@@ -284,60 +279,6 @@ public function type($type)
284279
return $this;
285280
}
286281

287-
/**
288-
* 开始时间
289-
* @param string $start
290-
* @return $this
291-
*/
292-
public function start($start)
293-
{
294-
$this->start = $start;
295-
return $this;
296-
}
297-
298-
/**
299-
* 结束时间
300-
* @param string $end
301-
* @return $this
302-
*/
303-
public function end($end)
304-
{
305-
$this->end = $end;
306-
return $this;
307-
}
308-
309-
/**
310-
* 间隔时间
311-
* @param string $step
312-
* @return $this
313-
*/
314-
public function step($step)
315-
{
316-
$this->step = $step;
317-
return $this;
318-
}
319-
320-
/**
321-
* 最小时间,小于该时间的时间段将被禁用
322-
* @param string $minTime
323-
* @return $this
324-
*/
325-
public function minTime($minTime)
326-
{
327-
$this->minTime = $minTime;
328-
return $this;
329-
}
330-
331-
/**
332-
* 最大时间,大于该时间的时间段将被禁用
333-
* @param mixed $maxTime
334-
* @return $this
335-
*/
336-
public function maxTime($maxTime)
337-
{
338-
$this->maxTime = $maxTime;
339-
return $this;
340-
}
341282

342283

343284
}

0 commit comments

Comments
 (0)