页面效果:
不喜欢废话,上代码:
先 npm i -S vuedraggable
再在页面中引用
<template>
<div class="fund1">
<van-sticky>
<ph-layout-header title="全部服务">
<template #left>
<img
class="leftarrow"
v-if="isShowIcon"
:src="$staticPath.getImage('/AccountOpen/leftarrow.png')"
@click="backHandle()"
/>
<span class="clone_text" v-else @click="closeHandle()">{{ '取消' }}</span>
</template>
<template #right @click="gotoPage('/enchashment/enchashment-index')">
<span v-if="isShowIcon" @click="clickIconHandle()" class="manage">管理</span>
<span v-else @click="preservationIconHandle()" class="manage">保存</span>
</template>
</ph-layout-header>
</van-sticky>
<div class="icon_index_box">
<p>首页服务</p>
<div class="col">
<!--
delay="100" 长按100之后才可以拖拽,因为会跟点击角标的 X号 事件有冲突
filter=".img-hover" class名为.img-hover 不可以拖拽
:disabled="disabled" 设置默认不可拖拽
-->
<draggable
v-model="cfgIconInfoDoListIndex"
delay="100"
filter=".img-hover"
animation="300"
:disabled="disabled"
:move="onMove"
>
<transition-group class="span_text">
<div v-for="(item, index) in cfgIconInfoDoListIndex" :key="item.id" class="img_box">
<div v-if="item.defaultFlag == '1'" class="img-hover">
<p>
<img
:src="item.iconUrl"
@click="isClick && gotoIconUrl(item.urlType, item.url)"
/>
</p>
<p>{{ item.iconName }}</p>
</div>
<div v-else class="img-hover1">
<p>
<img
:src="item.iconUrl"
@click="isClick && gotoIconUrl(item.urlType, item.url)"
/>
<img
:src="$staticPath.getImage('/TabMainPage/delete_icon.png')"
class="delete_img"
v-if="item.defaultFlag == '0' && !isShowIcon"
@click="deleteIconHandle(index)"
/>
</p>
<p>{{ item.iconName }}</p>
</div>
</div>
</transition-group>
</draggable>
</div>
<div class="tips">以上工具已显示在首页</div>
</div>
<div
class="icon_index_box"
style="border-bottom: none"
v-for="(value, key) in cfgIconInfoDoListAll"
:key="key"
>
<p style="margin-top: 28px">{{ key }}</p>
<div class="col">
<div class="span_text">
<div v-for="(item, i) in value" :key="item.id" class="img_box">
<div class="img-hover" @click="isClick && gotoIconUrl(item.urlType, item.url)">
<p>
<img :src="item.iconUrl" />
<img
:src="$staticPath.getImage('/TabMainPage/add_icon3.png')"
class="add_img"
v-if="!isShowIcon && hasCurrentIcon(item)"
@click="addIconHandle(key, i)"
/>
</p>
<p>{{ item.iconName }}</p>
</div>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
import draggable from 'vuedraggable';
export default {
components: {
draggable
},
data() {
return {
cfgIconInfoDoListIndex: [], // 首页显示图标
cfgIconInfoDoListNoFix: [],
cfgIconInfoDoListAll: {},
isShowIcon: true, //是否展示角标,
disabled: true,
isClick: true,
obj: {}
};
},
beforeCreate() {
document.querySelector('body').style.background = '#fdfbfb';
},
created() {
this.queryIconList();
},
mounted() {},
methods: {
/** 因为有默认icon不可拖拽,所以每行展示四个,如果只有三个默认icon的话,把可拖拽的托上面去就可以移动了,所以要给他不可移动 */
onMove(e) {
if (e.relatedContext.element.commonUseFlag == 1 && e.relatedContext.element.defaultFlag == 1)
return false;
return true;
},
/** 查询所有的数据 */
queryIconList() {
// var key = 'cfgIconInfoDoListAll';
// // 还是需要调用接口获取数据的 由于中台可配置的 登录后不一定就跟缓存的图标列表一致
// this.$mc
// .postForm('S15Q407', {}, { headers: { isStateError: false } })
// .then((res) => {
var obj = {
所有服务: [
{
updateDate: 1637078400000,
whiteType: null,
defaultFlag: '1',
funcUrlType: null,
iconName: '测试固定',
dataState: '1',
commonUseFlag: '1',
shelfBranch: '1',
url: 'https://www.baidu.com',
sortNo: 8,
createBy: 'admin',
urlType: '1',
updateBy: 'admin',
busiType: '所有服务',
iconCode: '009',
startTime: 'Tue Nov 16 00:00:00 CST 2021',
endTime: 'Tue Nov 30 00:00:00 CST 2021',
iconUrl:
'https://ajstg1.phfund.com.cn/apluswebcg/picture?path=L2FwbHVzL2ZpbGUvMjAyMTExMTcvOTEwNTQ2MjEyOTI1NzM5MDA5LnBuZw==',
id: '50facd29e2aa472c81ca6a1367a56f6f',
createDate: 1637078400000
},
{
updateDate: 1637078400000,
whiteType: null,
defaultFlag: '1',
funcUrlType: null,
iconName: '现金支付',
dataState: '1',
commonUseFlag: '1',
shelfBranch: '1',
url: null,
sortNo: 1,
createBy: 'admin',
urlType: '1',
updateBy: 'admin',
busiType: '所有服务',
iconCode: 'XJZF',
startTime: 'Mon Nov 01 00:00:00 CST 2021',
endTime: 'Sat Nov 12 00:00:00 CST 2022',
iconUrl:
'https://ajstg1.phfund.com.cn/apluswebcg/picture?path=L2FwbHVzL2ZpbGUvMjAyMTExMTcvOTEwNDc0NTM2NjI4MjYwODY0LnBuZw==',
id: '0909b09fcd514768b36b84bc0b7c07b4',
createDate: 1636646400000
},
{
updateDate: 1637078400000,
whiteType: null,
defaultFlag: '1',
funcUrlType: null,
iconName: '新手选基',
dataState: '1',
commonUseFlag: '1',
shelfBranch: '1',
url: null,
sortNo: 2,
createBy: 'admin',
urlType: '1',
updateBy: 'admin',
busiType: '所有服务',
iconCode: 'XSXJ',
startTime: 'Mon Nov 01 00:00:00 CST 2021',
endTime: 'Sun Nov 13 00:00:00 CST 2022',
iconUrl:
'https://ajstg1.phfund.com.cn/apluswebcg/picture?path=L2FwbHVzL2ZpbGUvMjAyMTExMTcvOTEwNDczNjI0ODE1OTMxMzkyLnBuZw==',
id: '79c5d2dd47e64e6c9ff27e6a7f244d36',
createDate: 1636732800000
},
{
updateDate: 1637078400000,
whiteType: null,
defaultFlag: '1',
funcUrlType: null,
iconName: '定投大会',
dataState: '1',
commonUseFlag: '1',
shelfBranch: '1',
url: null,
sortNo: 3,
createBy: 'admin',
urlType: '1',
updateBy: 'admin',
busiType: '所有服务',
iconCode: 'DTDH',
startTime: 'Mon Nov 01 00:00:00 CST 2021',
endTime: 'Sun Nov 13 00:00:00 CST 2022',
iconUrl:
'https://ajstg1.phfund.com.cn/apluswebcg/picture?path=L2FwbHVzL2ZpbGUvMjAyMTExMTcvOTEwNDczNTQ3OTU1MzEwNTk0LnBuZw==',
id: 'ab4e69af9aae4fe28ba7108b4c419d3d',
createDate: 1636732800000
},
{
updateDate: 1637078400000,
whiteType: null,
defaultFlag: '1',
funcUrlType: null,
iconName: '鹏华投顾',
dataState: '1',
commonUseFlag: '1',
shelfBranch: '1',
url: null,
sortNo: 4,
createBy: 'admin',
urlType: '1',
updateBy: 'admin',
busiType: '所有服务',
iconCode: 'PHTG',
startTime: 'Mon Nov 01 00:00:00 CST 2021',
endTime: 'Sun Nov 13 00:00:00 CST 2022',
iconUrl:
'https://ajstg1.phfund.com.cn/apluswebcg/picture?path=L2FwbHVzL2ZpbGUvMjAyMTExMTcvOTEwNDczNzA2Nzg5NDA4NzcwLnBuZw==',
id: '8a3fc07694324419b6c368885fa9bbb0',
createDate: 1636732800000
},
{
updateDate: 1637078400000,
whiteType: null,
defaultFlag: '0',
funcUrlType: null,
iconName: '群星闪耀',
dataState: '1',
commonUseFlag: '1',
shelfBranch: '1',
url: null,
sortNo: 12,
createBy: 'init',
urlType: '1',
updateBy: 'admin',
busiType: '所有服务',
iconCode: 'QXSY',
startTime: 'Mon Nov 01 00:00:00 CST 2021',
endTime: 'Sat Nov 12 00:00:00 CST 2022',
iconUrl:
'https://ajstg1.phfund.com.cn/apluswebcg/picture?path=L2FwbHVzL2ZpbGUvMjAyMTExMTcvOTEwNDczMzc4NDQ2NzA4NzM3LnBuZw==',
id: '001',
createDate: 1636646400000
},
{
updateDate: 1637078400000,
whiteType: null,
defaultFlag: '0',
funcUrlType: null,
iconName: '固收王牌',
dataState: '1',
commonUseFlag: '1',
shelfBranch: '1',
url: null,
sortNo: 10,
createBy: 'admin',
urlType: '1',
updateBy: 'admin',
busiType: '所有服务',
iconCode: 'GSWP',
startTime: 'Mon Nov 01 00:00:00 CST 2021',
endTime: 'Sun Nov 13 00:00:00 CST 2022',
iconUrl:
'https://ajstg1.phfund.com.cn/apluswebcg/picture?path=L2FwbHVzL2ZpbGUvMjAyMTExMTcvOTEwNDc0MTYyNTM0MDkyODAxLnBuZw==',
id: '99b1f933917941dbb09198ef5806cfeb',
createDate: 1636732800000
},
{
updateDate: 1637078400000,
whiteType: null,
defaultFlag: '1',
funcUrlType: null,
iconName: '优选指数',
dataState: '1',
commonUseFlag: '1',
shelfBranch: '1',
url: null,
sortNo: 7,
createBy: 'admin',
urlType: '1',
updateBy: 'admin',
busiType: '所有服务',
iconCode: 'YXZS',
startTime: 'Mon Nov 01 00:00:00 CST 2021',
endTime: 'Sun Nov 13 00:00:00 CST 2022',
iconUrl:
'https://ajstg1.phfund.com.cn/apluswebcg/picture?path=L2FwbHVzL2ZpbGUvMjAyMTExMTcvOTEwNDczODczMTk0MjI1NjY0LnBuZw==',
id: '3615f672c9c345ca81158c7e5125ec3e',
createDate: 1636732800000
},
{
updateDate: 1637078400000,
whiteType: null,
defaultFlag: '1',
funcUrlType: null,
iconName: '高端理财',
dataState: '1',
commonUseFlag: '1',
shelfBranch: '1',
url: null,
sortNo: 6,
createBy: 'admin',
urlType: '1',
updateBy: 'init',
busiType: '所有服务',
iconCode: 'GDLC',
startTime: 'Mon Nov 01 00:00:00 CST 2021',
endTime: 'Sun Nov 13 00:00:00 CST 2022',
iconUrl:
'https://ajstg1.phfund.com.cn/apluswebcg/picture?path=L2FwbHVzL2ZpbGUvMjAyMTExMTcvOTEwNDc0MDc0MzQ0NjU2ODk3LnBuZw==',
id: '6027e664f1d440e4931e45016088dbbc',
createDate: 1636732800000
},
{
updateDate: 1636992000000,
whiteType: null,
defaultFlag: '0',
funcUrlType: null,
iconName: 'sss',
dataState: '1',
commonUseFlag: '1',
shelfBranch: '1',
url: null,
sortNo: 9,
createBy: 'admin',
urlType: '2',
updateBy: 'admin',
busiType: '所有服务',
iconCode: '001',
startTime: 'Mon Nov 01 00:00:00 CST 2021',
endTime: 'Wed Nov 16 00:00:00 CST 2022',
iconUrl:
'https://ajstg1.phfund.com.cn/apluswebcg/picture?path=L2FwbHVzL2ZpbGUvMjAyMTExMTYvOTEwMjU1MTk1OTcwMzQyOTEyLnBuZw==',
id: '0e8ea5c47a0e4f49b2779ac3141ca558',
createDate: 1636992000000
},
{
updateDate: 1637078400000,
whiteType: null,
defaultFlag: '1',
funcUrlType: null,
iconName: 'ffff',
dataState: '1',
commonUseFlag: '1',
shelfBranch: '1',
url: null,
sortNo: 5,
createBy: 'admin',
urlType: '1',
updateBy: 'init',
busiType: '所有服务',
iconCode: '002',
startTime: 'Mon Nov 01 00:00:00 CST 2021',
endTime: 'Wed Nov 16 00:00:00 CST 2022',
iconUrl:
'https://ajstg1.phfund.com.cn/apluswebcg/picture?path=L2FwbHVzL2ZpbGUvMjAyMTExMTYvOTEwMjU1MzQ1OTUwMjY1MzQ0LnBuZw==',
id: '09ff99e9942b498798c96f6232cffc38',
createDate: 1636992000000
},
{
updateDate: 1636992000000,
whiteType: null,
defaultFlag: '0',
funcUrlType: null,
iconName: 'ggg',
dataState: '1',
commonUseFlag: '1',
shelfBranch: '1',
url: null,
sortNo: 11,
createBy: 'admin',
urlType: '1',
updateBy: 'admin',
busiType: '所有服务',
iconCode: '003',
startTime: 'Mon Nov 01 00:00:00 CST 2021',
endTime: 'Wed Nov 16 00:00:00 CST 2022',
iconUrl:
'https://ajstg1.phfund.com.cn/apluswebcg/picture?path=L2FwbHVzL2ZpbGUvMjAyMTExMTYvOTEwMjU1NDc3NjQzMDIyMzM2LnBuZw==',
id: '7d25c14b8c084ca1a39ca5585edd5077',
createDate: 1636992000000
},
{
updateDate: 1636992000000,
whiteType: null,
defaultFlag: '0',
funcUrlType: null,
iconName: '预约用钱',
dataState: '1',
commonUseFlag: '0',
shelfBranch: '1',
url: null,
sortNo: 12,
createBy: 'admin',
urlType: '1',
updateBy: 'admin',
busiType: '所有服务',
iconCode: '004',
startTime: 'Mon Nov 01 00:00:00 CST 2021',
endTime: 'Wed Nov 16 00:00:00 CST 2022',
iconUrl:
'https://ajstg1.phfund.com.cn/apluswebcg/picture?path=L2FwbHVzL2ZpbGUvMjAyMTExMTYvOTEwMjU1Njk2NzI0MTAzMTY5LnBuZw==',
id: '692417fbc1234274b0ab0ace7896a7eb',
createDate: 1636992000000
},
{
updateDate: 1636992000000,
whiteType: null,
defaultFlag: '0',
funcUrlType: null,
iconName: '定存工资',
dataState: '1',
commonUseFlag: '0',
shelfBranch: '1',
url: null,
sortNo: 13,
createBy: 'admin',
urlType: '1',
updateBy: 'admin',
busiType: '所有服务',
iconCode: '005',
startTime: 'Mon Nov 01 00:00:00 CST 2021',
endTime: 'Wed Nov 16 00:00:00 CST 2022',
iconUrl:
'https://ajstg1.phfund.com.cn/apluswebcg/picture?path=L2FwbHVzL2ZpbGUvMjAyMTExMTYvOTEwMjU1ODk1MTA2MjkzNzYyLnBuZw==',
id: '955ea1b343874af8b982a75b63e812d3',
createDate: 1636992000000
},
{
updateDate: 1636992000000,
whiteType: null,
defaultFlag: '0',
funcUrlType: null,
iconName: '优债宝',
dataState: '1',
commonUseFlag: '0',
shelfBranch: '1',
url: null,
sortNo: 14,
createBy: 'admin',
urlType: '1',
updateBy: 'admin',
busiType: '所有服务',
iconCode: '006',
startTime: 'Mon Nov 01 00:00:00 CST 2021',
endTime: 'Wed Nov 16 00:00:00 CST 2022',
iconUrl:
'https://ajstg1.phfund.com.cn/apluswebcg/picture?path=L2FwbHVzL2ZpbGUvMjAyMTExMTYvOTEwMjU2MTgxNDM0NjUwNjI1LnBuZw==',
id: 'edf251c63c874ea4a147b9e4568df60b',
createDate: 1636992000000
},
{
updateDate: 1636992000000,
whiteType: null,
defaultFlag: '0',
funcUrlType: null,
iconName: '公告公告',
dataState: '1',
commonUseFlag: '0',
shelfBranch: '1',
url: null,
sortNo: 15,
createBy: 'admin',
urlType: '1',
updateBy: 'admin',
busiType: '所有服务',
iconCode: '007',
startTime: 'Mon Nov 01 00:00:00 CST 2021',
endTime: 'Wed Nov 16 00:00:00 CST 2022',
iconUrl:
'https://ajstg1.phfund.com.cn/apluswebcg/picture?path=L2FwbHVzL2ZpbGUvMjAyMTExMTYvOTEwMjU2MzMzODU1NjU3OTg2LnBuZw==',
id: '62ef5e74ded14f00b79d3b44943fe0c1',
createDate: 1636992000000
},
{
updateDate: 1636992000000,
whiteType: null,
defaultFlag: '0',
funcUrlType: null,
iconName: '持仓秀',
dataState: '1',
commonUseFlag: '0',
shelfBranch: '1',
url: null,
sortNo: 16,
createBy: 'admin',
urlType: '1',
updateBy: 'admin',
busiType: '所有服务',
iconCode: '008',
startTime: 'Mon Nov 01 00:00:00 CST 2021',
endTime: 'Wed Nov 16 00:00:00 CST 2022',
iconUrl:
'https://ajstg1.phfund.com.cn/apluswebcg/picture?path=L2FwbHVzL2ZpbGUvMjAyMTExMTYvOTEwMjU2NjYyMTAxODg5MDI2LnBuZw==',
id: '3593dc4b51ad45a4985d5d73c46a98ec',
createDate: 1636992000000
}
]
};
this.cfgIconInfoDoListAll = obj;
Object.keys(this.cfgIconInfoDoListAll).forEach((item) => {
this.cfgIconInfoDoListAll[item].forEach((cfgitem) => {
if (cfgitem.commonUseFlag == '1') {
this.cfgIconInfoDoListIndex.push(cfgitem);
}
});
});
this.cfgIconInfoDoListIndex.sort((a, b) => {
return a.sortNo - b.sortNo;
});
// })
// .catch((error) => {});
},
hasCurrentIcon(item) {
/** 在首页数组里面查找传过来的iconCode,~ 波浪线是找到了,! 是取反,没找到的意思,没找到就不展示+号的角标 */
return !~this.cfgIconInfoDoListIndex.findIndex((f) => f.iconCode === item.iconCode);
},
clickIconHandle() {
if (this.$limit('clickIconHandle', 1)) return;
this.isShowIcon = false;
this.disabled = false;
this.isClick = false;
},
deleteIconHandle(index) {
if (this.$limit('deleteIconHandle', 1)) return;
var list = this.cfgIconInfoDoListIndex.splice(index, 1);
for (var k in this.cfgIconInfoDoListAll) {
for (var i = 0; i < this.cfgIconInfoDoListAll[k].length; i++) {
if (list[0].iconCode == this.cfgIconInfoDoListAll[k][i].iconCode) {
this.cfgIconInfoDoListAll[k][i].commonUseFlag = '0';
}
}
}
},
addIconHandle(key, index) {
if (this.$limit('addIconHandle', 1)) return;
this.cfgIconInfoDoListAll[key][index].commonUseFlag = '1';
if (this.cfgIconInfoDoListIndex.length < 12) {
for (var k in this.cfgIconInfoDoListAll) {
if (k == key) {
this.cfgIconInfoDoListIndex.push(this.cfgIconInfoDoListAll[k][index]);
}
}
} else {
this.$toast('首页功能最多不可以多于12个');
}
},
closeHandle() {
if (this.$limit('closeHandle', 1)) return;
this.isShowIcon = true;
this.disabled = true;
this.isClick = true;
var indexList = this.$storage.getItem('lastUserFuc');
var allList = this.$storage.getItem('cfgIconInfoDoListAll', true);
this.cfgIconInfoDoListIndex = indexList;
this.cfgIconInfoDoListAll = allList;
},
preservationIconHandle() {
if (this.cfgIconInfoDoListIndex.length < 0) {
this.$toast('请至少保存1个首页功能');
return;
}
for (var i = 0; i < this.cfgIconInfoDoListIndex.length; i++) {
this.cfgIconInfoDoListIndex[i].sortNo = i + 1;
}
var cfgIconInfoDoListNoFix = [];
this.cfgIconInfoDoListIndex.forEach((item) => {
if (item.defaultFlag == '0') {
cfgIconInfoDoListNoFix.push(item);
}
});
this.$storage.removeItem('cfgIconInfoDoListNoFix');
this.$storage.removeItem('cfgIconInfoDoListNoFix', true);
this.$storage.setItem('cfgIconInfoDoListNoFix.local', cfgIconInfoDoListNoFix);
this.$storage.setItem('cfgIconInfoDoListNoFix', cfgIconInfoDoListNoFix, true);
var data = {
cfgIconInfoReqList: this.cfgIconInfoDoListIndex
};
this.$mc
.postForm('S111158', data)
.then(() => {
this.isShowIcon = true;
this.disabled = true;
this.isClick = true;
this.$toast('保存成功');
})
.catch(() => {});
},
// icon栏目的跳转路径
gotoIconUrl() {
alert('跳转了');
},
backHandle() {
if (this.$limit('backHandle', 1)) return;
this.$pageBack();
}
},
watch: {
/** 监听拖拽后的数据变化 */
cfgIconInfoDoListIndex(indexValue) {
this.cfgIconInfoDoListIndex = indexValue;
}
},
filters: {}
};
</script>
<style lang="less" scoped>
.fund1 {
background: #fdfbfb;
}
.ph-layout-header {
background-color: #fdfbfb;
}
.manage {
font-family: PingFangSC-Medium;
font-size: 15px;
}
.leftarrow {
width: 11px;
}
.icon_index_box {
margin: 14px;
border-bottom: 1px solid #e7ebf0;
p:nth-child(1) {
font-size: 16px;
font-weight: 700;
color: #333;
font-family: PingFangSC-Medium;
}
.col {
flex: 0.25;
// width: 320px;
margin: 23px auto 0;
.span_text {
display: flex;
flex-wrap: wrap;
}
.img_box {
width: 25%;
text-align: center;
div {
flex: 1;
p:nth-child(1) {
margin: 0 auto;
position: relative;
.delete_img {
width: 21px;
height: 21px;
position: absolute;
top: 0;
}
img:nth-child(1) {
// width: 33px;
height: 32px;
}
.add_img:nth-child(2) {
width: 15px;
height: 15px;
position: absolute;
top: 0;
}
}
p:nth-child(2) {
color: #333333;
font-size: 13px;
font-family: PingFangSC-Regular;
margin-top: -2px;
}
}
}
.img_box1 {
width: 25%;
text-align: center;
div {
flex: 1;
p:nth-child(1) {
margin: 0 auto;
position: relative;
.delete_img {
width: 17px;
height: 17px;
position: absolute;
top: 0;
}
img:nth-child(1) {
// width: 33px;
height: 32px;
}
.add_img:nth-child(2) {
width: 12px;
height: 12px;
position: absolute;
top: 0;
}
}
p:nth-child(2) {
color: #333333;
font-size: 13px;
font-family: PingFangSC-Regular;
margin-top: -2px;
}
}
}
}
.tips {
color: #999999;
font-size: 12px;
text-align: center;
margin: 5px 0 15px 0px;
}
}
.clone_text {
font-size: 14px;
}
</style>