style:拖动
Showing
1 changed file
with
17 additions
and
44 deletions
| 1 | <!-- | 1 | <!-- |
| 2 | * @Description: | 2 | * @Description: |
| 3 | * @Autor: renchao | 3 | * @Autor: renchao |
| 4 | * @LastEditTime: 2023-09-13 10:18:32 | 4 | * @LastEditTime: 2023-09-13 10:33:50 |
| 5 | --> | 5 | --> |
| 6 | <template> | 6 | <template> |
| 7 | <div class="clmlmx-box"> | 7 | <div class="clmlmx-box"> |
| ... | @@ -9,7 +9,7 @@ | ... | @@ -9,7 +9,7 @@ |
| 9 | <el-button type="primary" icon="el-icon-top">上移</el-button> | 9 | <el-button type="primary" icon="el-icon-top">上移</el-button> |
| 10 | <el-button type="primary" icon="el-icon-bottom">下移</el-button> | 10 | <el-button type="primary" icon="el-icon-bottom">下移</el-button> |
| 11 | </div> | 11 | </div> |
| 12 | <lb-table :column="column" :key="key" :heightNumSetting="true" :calcHeight="600" | 12 | <lb-table :column="column" :key="key" row-key="bsmSj" ref="listTable" :heightNumSetting="true" :calcHeight="600" |
| 13 | :pagination="false" :data="tableData"> | 13 | :pagination="false" :data="tableData"> |
| 14 | </lb-table> | 14 | </lb-table> |
| 15 | <div class="text-center"> | 15 | <div class="text-center"> |
| ... | @@ -35,6 +35,7 @@ | ... | @@ -35,6 +35,7 @@ |
| 35 | data () { | 35 | data () { |
| 36 | return { | 36 | return { |
| 37 | loading: false, | 37 | loading: false, |
| 38 | sortable: null, | ||
| 38 | column: [ | 39 | column: [ |
| 39 | { | 40 | { |
| 40 | label: "选择", | 41 | label: "选择", |
| ... | @@ -168,6 +169,11 @@ | ... | @@ -168,6 +169,11 @@ |
| 168 | mounted () { | 169 | mounted () { |
| 169 | this.initSort() | 170 | this.initSort() |
| 170 | }, | 171 | }, |
| 172 | beforeDestroy () { | ||
| 173 | if (this.sortable) { | ||
| 174 | this.sortable.destroy(); | ||
| 175 | } | ||
| 176 | }, | ||
| 171 | methods: { | 177 | methods: { |
| 172 | handleSubmit () { | 178 | handleSubmit () { |
| 173 | this.loading = true | 179 | this.loading = true |
| ... | @@ -219,7 +225,6 @@ | ... | @@ -219,7 +225,6 @@ |
| 219 | * @description: 材料目录删除 | 225 | * @description: 材料目录删除 |
| 220 | * @param {*} index | 226 | * @param {*} index |
| 221 | * @param {*} row | 227 | * @param {*} row |
| 222 | * @author: renchao | ||
| 223 | */ | 228 | */ |
| 224 | handleDelete (index, row) { | 229 | handleDelete (index, row) { |
| 225 | if (row.children.length > 0) { | 230 | if (row.children.length > 0) { |
| ... | @@ -240,47 +245,15 @@ | ... | @@ -240,47 +245,15 @@ |
| 240 | }) | 245 | }) |
| 241 | }, | 246 | }, |
| 242 | initSort () { | 247 | initSort () { |
| 243 | const el = document.querySelectorAll('.el-table__body-wrapper > table > tbody')[0] | 248 | const el = this.$refs.listTable.$el.querySelectorAll('.el-table__body-wrapper > table > tbody')[0] |
| 244 | // const sortable = new Sortable(el, options); | 249 | this.sortable = Sortable.create(el, { |
| 245 | // 根据具体需求配置options配置项 | 250 | ghostClass: 'sortable-ghost', |
| 246 | const sortable = new Sortable(el, { | 251 | setData: function (dataTransfer) { |
| 247 | onEnd: (evt) => { // 监听拖动结束事件 | 252 | dataTransfer.setData('Text', '') |
| 248 | console.log(this) // this是当前vue上下文 | 253 | }, |
| 249 | console.log(evt.oldIndex) // 当前行的被拖拽前的顺序 | 254 | onEnd: evt => { |
| 250 | console.log(evt.newIndex) // 当前行的被拖拽后的顺序 | 255 | const targetRow = this.tableData.splice(evt.oldIndex, 1)[0]; |
| 251 | // 这里就可以写我们需要传给后台的逻辑代码 | 256 | this.tableData.splice(evt.newIndex, 0, targetRow); |
| 252 | // 我们有了 evt.oldIndex 和 evt.newIndex 这两个参数做索引,我们可以根据绑定在表格上面的 data 这个 Array 找到两个相应的记录。就可以针对数据进行操作啦。 | ||
| 253 | // 下面将拖拽后的顺序进行修改 | ||
| 254 | const currRow = this.tableData.splice(evt.oldIndex, 1)[0] | ||
| 255 | this.tableData.splice(evt.newIndex, 0, currRow) | ||
| 256 | const newData = [] | ||
| 257 | this.tableData.forEach((item, index) => { | ||
| 258 | newData[index] = { | ||
| 259 | id: item.id, | ||
| 260 | rank: index + 1 | ||
| 261 | } | ||
| 262 | }) | ||
| 263 | // 下面是将排序结果更新到数据库中,根据自己项目的逻辑进行实现即可。 | ||
| 264 | const data = { | ||
| 265 | id: this.$route.params.id, | ||
| 266 | datas: { | ||
| 267 | streams: newData | ||
| 268 | } | ||
| 269 | } | ||
| 270 | this.$store | ||
| 271 | .dispatch('user/setMultiSort', data) | ||
| 272 | .then((res) => { | ||
| 273 | if (res.code === 200) { | ||
| 274 | this.$message.success('排序修改成功') | ||
| 275 | // 修改成功后重新获取列表数据更新 | ||
| 276 | this.getMultiLiveList() | ||
| 277 | } else { | ||
| 278 | this.$message.error('排序修改失败') | ||
| 279 | } | ||
| 280 | }) | ||
| 281 | .catch((e) => { | ||
| 282 | console.log(e) | ||
| 283 | }) | ||
| 284 | } | 257 | } |
| 285 | }) | 258 | }) |
| 286 | } | 259 | } | ... | ... |
-
Please register or sign in to post a comment