|
1 | 1 | <template>
|
2 |
| - <span @click="handleClick"> |
3 |
| - <input type="checkbox" :name="name" title="写作" :value="label"> |
4 |
| - <div class="layui-unselect layui-form-checkbox " :class="{ |
5 |
| - 'layui-form-checked': hasValue, |
6 |
| - 'layui-radio-disbaled layui-disabled': disabled |
7 |
| - }" :lay-skin="primary ? 'primary' : ''"> |
8 |
| - <span><slot></slot></span> |
9 |
| - <i v-if="primary" class="layui-icon"></i> |
10 |
| - <i v-else class="layui-icon"></i> |
11 |
| - </div> |
| 2 | + <span> |
| 3 | + <span @click="handleClick"> |
| 4 | + <input type="checkbox" :name="name" title="写作" :value="label"> |
| 5 | + <div class="layui-unselect" :class="[{ |
| 6 | + 'layui-radio-disbaled layui-disabled': disabled |
| 7 | + }, |
| 8 | + skin == 'switch' ? 'layui-form-switch' : 'layui-form-checkbox', |
| 9 | + hasValue && skin == 'switch' ? 'layui-form-onswitch' : '', |
| 10 | + hasValue && skin != 'switch' ? 'layui-form-checked' : '']" :lay-skin="skin"> |
| 11 | + <span v-if="skin != 'switch'"><slot></slot></span> |
| 12 | + |
| 13 | + <em v-if="skin == 'switch'">{{text}}</em> |
| 14 | + <i v-if="skin == 'switch'"></i> |
| 15 | + |
| 16 | + <i v-if="skin == 'primary'" class="layui-icon"></i> |
| 17 | + <i v-if="!skin" class="layui-icon"></i> |
| 18 | + </div> |
| 19 | + </span> |
| 20 | + |
| 21 | + <!--<span v-if="skin && skin == 'switch'">--> |
| 22 | + <!--<input type="checkbox" name="open" lay-text="ON|OFF">--> |
| 23 | + <!--<div class="layui-unselect layui-form-switch layui-form-onswitch "--> |
| 24 | + <!--:class="{--> |
| 25 | + <!--'layui-form-checked': hasValue,--> |
| 26 | + <!--'layui-radio-disbaled layui-disabled': disabled--> |
| 27 | + <!--}"--> |
| 28 | + <!--lay-skin="_switch">--> |
| 29 | + <!--<em>ON</em>--> |
| 30 | + <!--<i></i>--> |
| 31 | + <!--</div>--> |
| 32 | + |
| 33 | + <!--<input type="checkbox" name="close" lay-skin="switch" lay-text="ON|OFF">--> |
| 34 | + <!--<div class="layui-unselect layui-form-switch" lay-skin="_switch">--> |
| 35 | + <!--<em>OFF</em><i></i>--> |
| 36 | + <!--</div>--> |
| 37 | + |
| 38 | + <!--</span>--> |
12 | 39 | </span>
|
13 | 40 |
|
| 41 | + |
| 42 | + |
14 | 43 | </template>
|
15 | 44 |
|
16 | 45 | <script>
|
17 | 46 | export default {
|
18 | 47 | name: 'layui-checkbox',
|
19 | 48 | data: function () {
|
20 | 49 | return {
|
21 |
| - hasValue: false |
| 50 | + hasValue: false, |
| 51 | + text: '' |
22 | 52 | }
|
23 | 53 | },
|
24 | 54 | props: {
|
25 | 55 | value: Array,
|
26 | 56 | label: [String, Number],
|
27 | 57 | disabled: Boolean,
|
28 | 58 | name: String,
|
29 |
| - primary: Boolean |
| 59 | + skin: [String], |
| 60 | + openText: [String], |
| 61 | + closeText: [String] |
30 | 62 | },
|
31 | 63 | methods: {
|
32 | 64 | handleClick: function () {
|
|
44 | 76 | }
|
45 | 77 | },
|
46 | 78 | created: function () {
|
47 |
| - this.value.includes(this.label) ? this.hasValue = true : this.hasValue = false |
| 79 | + if (this.value.includes(this.label)) { |
| 80 | + this.hasValue = true |
| 81 | + this.text = this.openText |
| 82 | + } else { |
| 83 | + this.hasValue = false |
| 84 | + this.text = this.closeText |
| 85 | + } |
48 | 86 | }
|
49 | 87 | }
|
50 | 88 | </script>
|
|
0 commit comments