Skip to content

Commit 9ae711a

Browse files
committed
修复Switch CheckBox 组件编辑时原始值不生效
1 parent ecc55ac commit 9ae711a

File tree

10 files changed

+66
-55
lines changed

10 files changed

+66
-55
lines changed

public/app.js

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ __webpack_require__.r(__webpack_exports__);
580580
//
581581
//
582582
//
583+
//
583584

584585
/* harmony default export */ __webpack_exports__["default"] = ({
585586
components: {
@@ -1183,7 +1184,6 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
11831184
//
11841185
//
11851186
//
1186-
//
11871187

11881188

11891189

@@ -1225,7 +1225,6 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
12251225
destroyed: function destroyed() {
12261226
try {
12271227
this.$bus.off("tableReload");
1228-
window.removeEventListener("keydown", this.onEnt);
12291228
} catch (e) {}
12301229
},
12311230
methods: {
@@ -1290,14 +1289,6 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
12901289
if (event.keyCode === 13) {
12911290
this.getData();
12921291
}
1293-
},
1294-
onQuickSearchFocus: function onQuickSearchFocus() {
1295-
window.addEventListener("keydown", this.onEnt);
1296-
},
1297-
onQuickSearchBlur: function onQuickSearchBlur() {
1298-
try {
1299-
window.removeEventListener("keydown", this.onEnt);
1300-
} catch (error) {}
13011292
}
13021293
},
13031294
computed: {
@@ -1946,6 +1937,9 @@ __webpack_require__.r(__webpack_exports__);
19461937
//
19471938
//
19481939
//
1940+
//
1941+
//
1942+
//
19491943
/* harmony default export */ __webpack_exports__["default"] = ({
19501944
props: {
19511945
attrs: Object,
@@ -1954,9 +1948,7 @@ __webpack_require__.r(__webpack_exports__);
19541948
}
19551949
},
19561950
data: function data() {
1957-
return {
1958-
vm: ""
1959-
};
1951+
return {};
19601952
},
19611953
model: {
19621954
prop: "value",
@@ -2708,12 +2700,11 @@ __webpack_require__.r(__webpack_exports__);
27082700
props: {
27092701
attrs: Object,
27102702
value: {
2711-
"default": null
2703+
"default": true
27122704
}
27132705
},
27142706
data: function data() {
27152707
return {
2716-
vm: "",
27172708
options: this.attrs.options
27182709
};
27192710
},
@@ -5009,7 +5000,7 @@ exports = module.exports = __webpack_require__(/*! ../../../../node_modules/css-
50095000

50105001

50115002
// module
5012-
exports.push([module.i, ".form-page .form-card {\n min-height: 200px;\n}\n.form-page .el-form-item__content {\n line-height: unset;\n}\n.form-page .form-bottom-actions {\n display: flex;\n align-items: center;\n justify-content: space-between;\n}\n.form-page .form-bottom-actions .submit-btn {\n width: 120px;\n}\n.form-page .form-item-help {\n color: #999;\n}", ""]);
5003+
exports.push([module.i, ".form-page .form-card {\n min-height: 200px;\n}\n.form-page .form-bottom-actions {\n display: flex;\n align-items: center;\n justify-content: space-between;\n}\n.form-page .form-bottom-actions .submit-btn {\n width: 120px;\n}\n.form-page .form-item-help {\n color: #999;\n}", ""]);
50135004

50145005
// exports
50155006

@@ -26917,6 +26908,14 @@ var render = function() {
2691726908
? _c(
2691826909
"el-form",
2691926910
{
26911+
directives: [
26912+
{
26913+
name: "loading",
26914+
rawName: "v-loading",
26915+
value: _vm.loading,
26916+
expression: "loading"
26917+
}
26918+
],
2692026919
ref: "ruleForm",
2692126920
class: _vm.attrs.attrs.className,
2692226921
style: _vm.attrs.attrs.style,
@@ -27394,10 +27393,23 @@ var render = function() {
2739427393
placeholder: _vm.attrs.quickSearch.placeholder,
2739527394
clearable: true
2739627395
},
27397-
on: {
27398-
clear: _vm.getData,
27399-
focus: _vm.onQuickSearchFocus,
27400-
blur: _vm.onQuickSearchBlur
27396+
on: { clear: _vm.getData },
27397+
nativeOn: {
27398+
keyup: function($event) {
27399+
if (
27400+
!$event.type.indexOf("key") &&
27401+
_vm._k(
27402+
$event.keyCode,
27403+
"enter",
27404+
13,
27405+
$event.key,
27406+
"Enter"
27407+
)
27408+
) {
27409+
return null
27410+
}
27411+
return _vm.getData($event)
27412+
}
2740127413
},
2740227414
model: {
2740327415
value: _vm.quickSearch,
@@ -28366,7 +28378,9 @@ var render = function() {
2836628378
class: _vm.attrs.className,
2836728379
style: _vm.attrs.style,
2836828380
attrs: {
28381+
value: _vm.value,
2836928382
label: _vm.attrs.label,
28383+
"true-label": _vm.attrs.label,
2837028384
disabled: _vm.attrs.disabled,
2837128385
border: _vm.attrs.border,
2837228386
size: _vm.attrs.size,
@@ -29034,6 +29048,7 @@ var render = function() {
2903429048
class: _vm.attrs.className,
2903529049
style: _vm.attrs.style,
2903629050
attrs: {
29051+
value: _vm.value,
2903729052
disabled: _vm.attrs.disabled,
2903829053
width: _vm.attrs.width,
2903929054
"active-icon-class": _vm.attrs.activeIconClass,
@@ -29047,14 +29062,7 @@ var render = function() {
2904729062
name: _vm.attrs.name,
2904829063
"validate-event": _vm.attrs.validateEvent
2904929064
},
29050-
on: { change: _vm.onChange },
29051-
model: {
29052-
value: _vm.vm,
29053-
callback: function($$v) {
29054-
_vm.vm = $$v
29055-
},
29056-
expression: "vm"
29057-
}
29065+
on: { change: _vm.onChange }
2905829066
})
2905929067
}
2906029068
var staticRenderFns = []

public/mix-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"/app.js": "/app.js?id=fe8a9b23760b6394bc45",
2+
"/app.js": "/app.js?id=002f63ad8c850b9ab4e4",
33
"/manifest.js": "/manifest.js?id=d9708e48a6c10ccee4bb",
44
"/vendor.js": "/vendor.js?id=f4679ac178c0e413cb28"
55
}

resources/js/components/form/BaseForm.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<div class="form-page">
33
<el-card shadow="never" class="form-card">
44
<el-form
5+
v-loading="loading"
56
v-if="formData"
67
ref="ruleForm"
78
:model="formData"
@@ -168,7 +169,7 @@ export default {
168169
min-height: 200px;
169170
}
170171
.el-form-item__content {
171-
line-height: unset;
172+
//line-height: unset;
172173
}
173174
.form-bottom-actions {
174175
display: flex;

resources/js/components/grid/Table.vue

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@
1515
:placeholder="attrs.quickSearch.placeholder"
1616
:clearable="true"
1717
@clear="getData"
18+
@keyup.enter.native="getData"
1819
v-if="attrs.quickSearch"
19-
@focus="onQuickSearchFocus"
20-
@blur="onQuickSearchBlur"
2120
>
2221
<el-button @click="getData" :loading="loading" slot="append"
2322
>搜索</el-button
@@ -205,7 +204,6 @@ export default {
205204
destroyed() {
206205
try {
207206
this.$bus.off("tableReload");
208-
window.removeEventListener("keydown", this.onEnt);
209207
} catch (e) {}
210208
},
211209
methods: {
@@ -264,14 +262,6 @@ export default {
264262
if (event.keyCode === 13) {
265263
this.getData();
266264
}
267-
},
268-
onQuickSearchFocus() {
269-
window.addEventListener("keydown", this.onEnt);
270-
},
271-
onQuickSearchBlur() {
272-
try {
273-
window.removeEventListener("keydown", this.onEnt);
274-
} catch (error) {}
275265
}
276266
},
277267
computed: {

resources/js/components/widgets/Checkbox.vue

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
<template>
22
<el-checkbox
3+
:value="value"
34
:style="attrs.style"
45
:class="attrs.className"
56
:label="attrs.label"
7+
:true-label="attrs.label"
68
:disabled="attrs.disabled"
79
:border="attrs.border"
810
:size="attrs.size"
911
:indeterminate="attrs.indeterminate"
1012
@change="onChange"
11-
>{{attrs.title}}</el-checkbox>
13+
>{{ attrs.title }}</el-checkbox
14+
>
1215
</template>
1316
<script>
1417
export default {
@@ -19,9 +22,7 @@ export default {
1922
}
2023
},
2124
data() {
22-
return {
23-
vm: ""
24-
};
25+
return {};
2526
},
2627
model: {
2728
prop: "value",
@@ -33,4 +34,4 @@ export default {
3334
}
3435
}
3536
};
36-
</script>
37+
</script>

resources/js/components/widgets/Switch.vue

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<el-switch
3-
v-model="vm"
3+
:value="value"
44
:style="attrs.style"
55
:class="attrs.className"
66
:disabled="attrs.disabled"
@@ -23,12 +23,11 @@ export default {
2323
props: {
2424
attrs: Object,
2525
value: {
26-
default: null
26+
default: true
2727
}
2828
},
2929
data() {
3030
return {
31-
vm: "",
3231
options: this.attrs.options
3332
};
3433
},
@@ -42,4 +41,4 @@ export default {
4241
}
4342
}
4443
};
45-
</script>
44+
</script>

src/Components/CSwitch.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ static public function make($value = null)
2626
return new CSwitch($value);
2727
}
2828

29+
public function getValue($value)
30+
{
31+
return boolval($value);
32+
}
33+
2934
/**
3035
* 是否禁用
3136
* @param bool $disabled

src/Form.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,8 @@ public function editData($id)
599599
foreach ($this->formItems as $formItem) {
600600
$field = $formItem->getField();
601601
$prop = $formItem->getProp();
602-
Arr::set($data, $prop, $formItem->getData(Arr::get($e_data, $prop), $this->model));
602+
$component = $formItem->getDisplayComponent();
603+
Arr::set($data, $prop, $formItem->getData(Arr::get($e_data, $prop), $this->model,$component));
603604
//$data[$prop] = $formItem->getData($e_data->{$prop}, $this->model);
604605
}
605606
foreach ($this->formItems as $formItem) {

src/Form/FormItem.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ public function displayComponent($component)
9090
return $this;
9191
}
9292

93+
public function getDisplayComponent()
94+
{
95+
return $this->component;
96+
}
97+
9398
/**
9499
* @return mixed
95100
*/
@@ -192,9 +197,12 @@ public function getCopyProp()
192197
return $this->copyProp;
193198
}
194199

195-
public function getData($data, $model)
200+
public function getData($data, $model, $component)
196201
{
197202
if (!method_exists($model, $this->prop)) {
203+
if (method_exists($component, "getValue")) {
204+
return $component->getValue($data);
205+
}
198206
return $data;
199207
} else {
200208
if ($model->{$this->prop}() instanceof BelongsToMany) {
@@ -277,8 +285,6 @@ public function inputWidth(int $inputWidth)
277285
}
278286

279287

280-
281-
282288
/**
283289
* 是否必填,如不设置,则会根据校验规则自动生成
284290
* @param bool $required

src/Grid/Tools/QuickSearch.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class QuickSearch implements JsonSerializable
88
{
99
public $searchKey = '__search__';
10-
public $placeholder;
10+
public $placeholder = "输入搜索关键字";
1111
/**
1212
* @var array|string|\Closure
1313
*/

0 commit comments

Comments
 (0)