1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
| <!DOCTYPE html> <html lang="en">
<head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script src="https://cdn.jsdelivr.net/gh/Rr210/[email protected]/js/jquery-3.5.1.min.js"></script> <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Rr210/[email protected]/frame/bootstrap/3/css/bootstrap.min.css"> <script src="https://cdn.jsdelivr.net/gh/Rr210/[email protected]/frame/bootstrap/3/js/bootstrap.min.js"></script> <title>Document</title> </head> <style> body { padding: 0; margin: 0; box-sizing: border-box; }
.tab { margin: 100px auto; }
.checkOn { overflow: hidden; width: 66px; height: 25px; line-height: 25px; border-radius: 20px; border: 1px solid #888; font-size: 8px; }
.check_warp { position: relative; }
input[id^="check"][type="checkbox"] { position: absolute; width: 100%; height: 100%; top: 0; left: 0; opacity: 0; }
.on { float: left; width: 23px; height: 23px; line-height: 23px; border-radius: 50%; background-color: #ccc; color: #000; }
.isChecked { background-color: #fff; }
.isbg { color: #fff; background-color: rgb(0, 110, 255); }
.form_data { margin: 20px 0; }
#btn1 { outline: none; } </style>
<body> <div class="tab container text-center" id="app"> <h2>汽车品牌列表</h2> <form class="form-inline form_data" @submit.prevent="add"> <div class="form-group"> <label class="sr-only" for="exampleInputAmount">Amount (in dollars)</label> <div class="input-group"> <div class="input-group-addon">请输入品牌</div> <input type="text" class="form-control" id="exampleInputAmount" name="brand_name" placeholder="请输入要添加的品牌"> </div> </div> <button class="btn btn-primary" id="btn1" type="submit">添加</button> <a class="" tabindex="0" class="btn btn-lg btn-danger" role="button" id='btn2' data-toggle="popover" data-trigger="" data-delay="show:500;hide:400" title="提示" data-content=""></a> </form> <table class="table table-striped table-bordered justify-content-center table-hover"> <thead> <tr> <th class="text-center" v-for="(item,index) in th_title">{{item}}</th> </tr> </thead> <tbody> <tr v-for="(item,index) in brandList" :key="item.id"> <td>{{index+1}}</td> <td>{{item.brand_name}}</td> <td> <div class="check_warp"> <label :for="'check'+item.id" :class="item.status?'checkOn isbg':'checkOn'"> <div :class="item.status?'on isChecked':'on'" :style="item.status?'float:right':'float:left'"></div> {{item.status?'已启用':'已禁用'}} </label> <input @change="getFloat" :data-index='index' type="checkbox" :checked="item.status" name="status" :id="'check' + item.id"> </div> </td> <td>{{item.time | formatDate}}</td> <td><button @click="remove(index)">移除</button></td> </tr> </tbody> </table> </div> </body> <script src="../../js/vue.js"></script> <script> const app = new Vue({ el: '#app', data: { th_title: ['#', '品牌名称', '状态', '创建时间', '操作'], brandList: [{ id: 0, brand_name: '宝马', status: true, time: new Date() }, { id: 1, brand_name: '奔驰', status: false, time: new Date() }, { id: 2, brand_name: '奥迪', status: true, time: new Date() }, { id: 3, brand_name: '路虎', status: true, time: new Date() } ] }, methods: { getFloat(e) { let { checked } = e.target let { index } = e.target.dataset this.brandList[index].status = checked }, remove(index) { this.brandList.splice(index, 1) }, add(e) { let timer; let brand_name = $('#exampleInputAmount').val().trim() if (brand_name.length == 0) { this.getmodal('您输入的内容为空,请重新输入!!') } else { this.brandList.push({ id: this.brandList.length, brand_name, status: false, time: new Date() }) this.getmodal('品牌已成功添加到列表中') } }, getmodal(content) { $('.popover-content').text('') $('#btn2').data('content', content).popover('show') timer = setTimeout(function() { $('#btn2').popover('destroy') }, 2500) } }, filters: { formatDate: function(now) { var year = now.getFullYear(); var month = now.getMonth() + 1; var date = now.getDate(); var hour = now.getHours(); var minute = now.getMinutes(); var second = now.getSeconds(); return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second; } } }) </script>
</html>
|