Skip to content

Commit b2328d7

Browse files
Merge pull request #6 from osindex/develop
🎨 Select远程搜索;vif;AuthApi
2 parents 634b85e + 6eed1cd commit b2328d7

File tree

9 files changed

+115
-15
lines changed

9 files changed

+115
-15
lines changed

docs/components.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,17 @@ Select::make()
398398

399399
```php
400400
Select::make()->filterable()->remote($remoteUrl)
401+
Select::make()->filterable()->remote($remoteUrl)->extUrlParams(['type'=>'A']) // 远程搜索带参数
402+
Select::make()->filterable()->remote($remoteUrl)->depend(['keyA','keyB.0.key']) // 远程搜索带表单值
403+
Select::make()->filterable()->remote($remoteUrl)->paginate($per_page = 10) // 远程搜索带分页加载
404+
```
405+
406+
支持
407+
408+
```php
409+
410+
411+
401412
```
402413

403414
更多属性请查看element-ui文档

docs/form.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ $form->item('username', '用户名')->serveRulesMessage(["required" => '必填']
190190

191191
```php
192192
$form->item('username', '用户名')->vif("key","value")
193+
$form->item('username', '用户名')->vif("email",false,true) // 表示填写email任意字符之后才会出现username 注意第二个参数最好不要用null或者可能存在的值
193194
$form->item('username', '用户名')->vif("key.key","value") //支持点操作
194195
```
195196

docs/thirdparty.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@
1010

1111
## 全局组件
1212

13+
## 其它扩展
14+
* [AuthApi](https://github.com/osindex/laravel-auth-api)基于`laravel/sanctum`的API认证方案,支持多用户。

resources/js/components/form/Form.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ export default {
161161
this.$refs[formName].validate(valid => {
162162
if (valid) {
163163
this.loading = true;
164-
console.log(this.ignoreKey)
165164
const formatData = this._.pick(this.formData, this.ignoreKey)
166165
if (this.isEdit) {
167166
this.$http

resources/js/components/form/ItemIf.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ export default {
1414
ifShow() {
1515
let key = this.form_item.vif.key;
1616
let value = this.form_item.vif.value;
17-
17+
let anyValue = this.form_item.vif.anyValue;
1818
if (key) {
1919
let cValue = window._.get(this.form_data, key);
20-
if (cValue == value) {
20+
if (cValue == value || (cValue && anyValue)) {
2121
return true;
2222
} else {
2323
return false;
2424
}
2525
}
2626
27-
return true;
27+
return !anyValue;
2828
}
2929
}
3030
};

resources/js/components/widgets/Select.vue

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@
4747
<div class="flex-c" v-if="item.desc" v-html="item.desc"></div>
4848
</div>
4949
</el-option>
50+
<el-option v-if="attrs.paginate && loadMore && options.length" :value="undefined">
51+
<div @click.stop='paginateData($event)'>
52+
<i class="el-icon-loading"></i>
53+
<span>加载更多</span>
54+
</div>
55+
</el-option>
5056
</el-select>
5157
</template>
5258
<script>
@@ -60,23 +66,61 @@ export default {
6066
},
6167
data() {
6268
return {
63-
options: this.attrs.options
69+
options: this.attrs.options,
70+
extUrlParams: this.attrs.extUrlParams,
71+
query: null,
72+
loadMore: true,
73+
meta: {
74+
page: 1,
75+
per_page: this.attrs.paginate
76+
}
6477
};
6578
},
6679
model: {
6780
prop: "value",
6881
event: "change"
6982
},
83+
computed: {
84+
depend() {
85+
return _.pick(this.form_data, this.attrs.depend);
86+
}
87+
},
7088
methods: {
7189
onChange(value) {
72-
this.$emit("change", value);
90+
let resValue = value
91+
if(typeof value === 'object'){
92+
// 排除value = 0
93+
resValue = value.filter(e=> e !== undefined)
94+
}else if(value === undefined){
95+
resValue = null
96+
}
97+
this.$emit("change", resValue);
7398
},
7499
remoteMethod(query) {
100+
this.query = query
101+
this.meta.page = 1
75102
this.$http
76-
.get(this.attrs.remoteUrl, { params: { query: query } })
103+
.get(this.attrs.remoteUrl, { params: { ...this.meta, query: query, depend: this.depend, extUrlParams: this.extUrlParams } })
77104
.then(res => {
78105
this.options = res.data;
106+
this.meta.page++
107+
this.loadMore = true
79108
});
109+
},
110+
paginateData(event) {
111+
this.$http
112+
.get(this.attrs.remoteUrl, { params: { ...this.meta, query: this.query, depend: this.depend, extUrlParams: this.extUrlParams } })
113+
.then(res => {
114+
if (res.data.length) {
115+
this.options.push(...res.data)
116+
}
117+
if(this.meta.page < res.meta.to){
118+
this.meta.page = res.meta.to
119+
this.loadMore = true
120+
}else{
121+
this.loadMore = false
122+
}
123+
})
80124
}
81125
}
82126
};

src/Components/Attrs/Depend.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace SmallRuralDog\Admin\Components\Attrs;
4+
5+
trait Depend
6+
{
7+
protected $depend;
8+
protected $paginate = 0;
9+
protected $extUrlParams;
10+
11+
/**
12+
* @param mixed $depend
13+
* @return $this
14+
*/
15+
public function depend($depend)
16+
{
17+
$this->depend = $depend;
18+
return $this;
19+
}
20+
21+
/**
22+
* @param mixed $paginate
23+
* @return $this
24+
*/
25+
public function paginate($paginate)
26+
{
27+
$this->paginate = $paginate;
28+
return $this;
29+
}
30+
/**
31+
* @param mixed $extUrlParams
32+
* @return $this
33+
*/
34+
public function extUrlParams($extUrlParams)
35+
{
36+
$this->extUrlParams = $extUrlParams;
37+
return $this;
38+
}
39+
}

src/Components/Select.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<?php
22

3-
43
namespace SmallRuralDog\Admin\Components;
54

5+
use SmallRuralDog\Admin\Components\Attrs\Depend;
66

77
class Select extends Component
88
{
9+
use Depend;
910
public $componentName = 'Select';
1011

11-
1212
protected $multiple = false;
1313

1414
protected $disabled = false;
@@ -38,7 +38,7 @@ class Select extends Component
3838
*/
3939
protected $options = [];
4040

41-
static public function make($value = null)
41+
public static function make($value = null)
4242
{
4343
return new Select($value);
4444
}
@@ -52,14 +52,13 @@ public function block($block = true)
5252
{
5353
if ($block) {
5454
$style = collect($this->style)->add([
55-
'display' => 'block'
55+
'display' => 'block',
5656
]);
5757
$this->style($style);
5858
}
5959
return $this;
6060
}
6161

62-
6362
/**
6463
* 是否多选
6564
* @param bool $multiple
@@ -68,7 +67,10 @@ public function block($block = true)
6867
public function multiple($multiple = true)
6968
{
7069
$this->multiple = $multiple;
71-
if (!$this->componentValue) $this->componentValue([]);
70+
if (!$this->componentValue) {
71+
$this->componentValue([]);
72+
}
73+
7274
return $this;
7375
}
7476

@@ -176,7 +178,7 @@ public function filterable($filterable = true)
176178
* @param string $allowCreateUrl 创建新条目Url
177179
* @return $this
178180
*/
179-
public function allowCreate($allowCreateUrl=null)
181+
public function allowCreate($allowCreateUrl = null)
180182
{
181183
$this->allowCreate = true;
182184
$this->filterable = true;

src/Form/FormItem.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class FormItem
4949
protected $vif = [
5050
'key' => null,
5151
'value' => null,
52+
'anyValue' => false,
5253
];
5354

5455
/**
@@ -441,11 +442,12 @@ public function help($help)
441442
* @param $value
442443
* @return $this
443444
*/
444-
public function vif($key, $value)
445+
public function vif($key, $value, $anyValue = false)
445446
{
446447
$this->vif = [
447448
'key' => $key,
448449
'value' => $value,
450+
'anyValue' => $anyValue,
449451
];
450452
return $this;
451453
}

0 commit comments

Comments
 (0)