Skip to content

Commit e04fda0

Browse files
committed
opt code
1 parent 0eb4775 commit e04fda0

3 files changed

Lines changed: 70 additions & 8 deletions

File tree

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"axios": "^0.21.0",
1313
"element-ui": "^2.13.2",
1414
"js-md5": "^0.7.3",
15+
"sortablejs": "^1.14.0",
1516
"url-loader": "^4.1.0",
1617
"vue": "^2.5.11"
1718
},

src/components/Iptv.vue

Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
placeholder="source"
88
@change="hanldeTrans"
99
v-model="source"></el-input>
10-
<!-- <el-button size="mini" type="success" @click="hanldeTrans">点击转换</el-button> -->
11-
<el-button size="mini" type="info" @click="getData" v-if="selectedList.length > 0">
10+
<el-button size="mini" type="info" @click="getData"
11+
v-if="selectedList.length > 0 || (nowIsSort && this.list.length > 0)">
1212
下载json
1313
</el-button>
14+
<el-button size="mini" type="info" @click="doSort">整理源</el-button>
1415
<el-button size="mini" @click="fetchData" v-if="this.list.length > 0 && !nowIsCheck">
1516
检查链接是否正常
1617
</el-button>
@@ -25,9 +26,16 @@
2526
:rows="2"
2627
v-model="selectedData"></el-input>
2728
</div>
29+
<div class="sort-container" v-show="nowIsSort">
30+
<ul id="items" class="sort-ul">
31+
<li class="item-li" v-for="(value, index) in list" :key="index">
32+
{{index+1}}. {{value.name}} <el-link @click="doDelete(index)">删除</el-link>
33+
</li>
34+
</ul>
35+
</div>
2836
<div>
2937
<el-table
30-
v-if="list.length > 0"
38+
v-if="list.length > 0 && !nowIsSort"
3139
ref="dataTable"
3240
@selection-change="handleSelectionChange"
3341
:data="list"
@@ -54,7 +62,6 @@
5462
label="tvg-language">
5563
<template slot-scope="scope">
5664
<div>{{scope.row.name}}</div>
57-
<!-- <img height="20" :src="scope.row.tvgLogo" > -->
5865
</template>
5966
</el-table-column>
6067
<el-table-column
@@ -88,6 +95,7 @@
8895
</div>
8996
</template>
9097
<script>
98+
import Sortable from 'sortablejs';
9199
import { fetchGet } from '../utils/axios';
92100
93101
export default {
@@ -101,6 +109,7 @@ export default {
101109
selectedList: [],
102110
nowCheckCount: 0,
103111
nowIsCheck: false,
112+
nowIsSort: false,
104113
};
105114
},
106115
watch: {
@@ -110,17 +119,54 @@ export default {
110119
}
111120
},
112121
},
122+
mounted() {
123+
this.parseList();
124+
},
113125
methods: {
126+
doDelete(index) {
127+
this.list.splice(index, 1);
128+
},
129+
doSort() {
130+
if (this.nowIsSort) {
131+
this.nowIsSort = false;
132+
} else {
133+
this.nowIsSort = true;
134+
this.enableSort();
135+
}
136+
},
137+
enableSort() {
138+
const el = document.getElementById('items');
139+
const _this = this;
140+
Sortable.create(el, {
141+
onEnd({ newIndex, oldIndex }) {
142+
const current = _this.list.splice(oldIndex, 1)[0];
143+
_this.list.splice(newIndex, 0, current);
144+
const rows = _this.list;
145+
_this.list = [];
146+
setTimeout(() => {
147+
_this.list = rows;
148+
}, 5);
149+
},
150+
});
151+
},
114152
handleSelectionChange(val) {
115153
this.selectedList = val;
116154
this.selectedData = '';
117155
},
118156
getData() {
119-
let name = `${this.firstTitle}\n`;
120-
for (let i = 0; i < this.selectedList.length; i += 1) {
121-
name += `${this.selectedList[i].originalData}\n`;
157+
if (this.nowIsSort) {
158+
let name = `${this.firstTitle}\n`;
159+
for (let i = 0; i < this.list.length; i += 1) {
160+
name += `${this.list[i].originalData}\n`;
161+
}
162+
this.selectedData = name;
163+
} else {
164+
let name = `${this.firstTitle}\n`;
165+
for (let i = 0; i < this.selectedList.length; i += 1) {
166+
name += `${this.selectedList[i].originalData}\n`;
167+
}
168+
this.selectedData = name;
122169
}
123-
this.selectedData = name;
124170
},
125171
autoSelect() {
126172
for (let i = 0; i < this.list.length; i += 1) {
@@ -241,4 +287,14 @@ export default {
241287
</script>
242288
<style lang="sass" scoped>
243289
.iptv-container
290+
.sort-container
291+
.sort-ul
292+
display: flex;
293+
flex-direction: column;
294+
.item-li
295+
justify-content: space-between;
296+
width: 400px
297+
padding: 10px;
298+
display: flex;
299+
border-bottom: 1px solid #000
244300
</style>

0 commit comments

Comments
 (0)