123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- <template>
- <view class="zaiui-scroll-view-box">
- <scroll-view class="zaiui-scroll-view" scroll-x @scroll="navScroll">
- <view id="scroll1" class="zaiui-scroll-view-item">
- <view class="cu-list grid col-5 no-border">
- <block v-for="(item,index) in ListData" :key="index" v-if="index < 10">
- <view class="cu-item" @tap="listTap(item,index)">
- <view class="grid-icon">
- <image class="icon" :src="item.icon || '/static/zaiui/img/more.png'" mode="widthFix"/>
- </view>
- <view class="cu-tag badge z" :class="['bg-' + item.color]" v-if="item.badge">{{item.badge}}</view>
- <text class="text-black">{{item.name}}</text>
- </view>
- </block>
- </view>
- </view>
- <view id="scroll2" class="zaiui-scroll-view-item" v-if="ListData.length > 10">
- <view class="cu-list grid col-5 no-border">
- <block v-for="(item,index) in ListData" :key="index" v-if="index >= 10">
- <view class="cu-item" @tap="listTap(item,index)">
- <view class="grid-icon">
- <image class="icon" :src="item.icon || '/static/zaiui/img/more.png'" mode="widthFix" style="max-height: 44px;"></image>
- </view>
- <view class="cu-tag badge z" :class="['bg-' + item.color]" v-if="item.badge">{{item.badge}}</view>
- <text class="text-black">{{item.name}}</text>
- </view>
- </block>
- </view>
- </view>
- </scroll-view>
- <view class="zaiui-scroll-h-view" :style="{width: `${scrollPage * 16}px`}">
- <view class="box">
- <view class="bg-red dot" :style="{left: `${scrollDot}px`}"></view>
- </view>
- </view>
- </view>
- </template>
- <script>
- import _tool from '@/static/zaiui/util/tools.js';
- export default {
- name: 'grid-menu-list',
- data() {
- return {
- ListData: [], scrollPage: 1, scrollDot: 0,
- };
- },
- props: {
- list_data: {
- type: Array,
- default: () => {
- return []
- }
- }
- },
- created() {
- this.ListData = this.list_data;
- this.getScrollPageNum();
- },
- watch: {
- list_data() {
- this.ListData = this.list_data;
- this.getScrollPageNum();
- }
- },
- methods: {
- getScrollPageNum() {
- this.scrollPage = _tool.getPageNum(this.ListData.length,10);
- },
- navScroll(e) {
- //计算公式: 移动距离 /(A总 / B总)
- let pageWidth = this.scrollPage * 16;
- let Width = e.detail.scrollWidth / pageWidth;
- this.scrollDot = e.detail.scrollLeft / Width;
- },
- listTap(data,index) {
- this.$emit('listTap', {
- data,
- index
- });
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .zaiui-scroll-view-box {
- position: relative;
- .zaiui-scroll-view {
- position: relative;
- // height: 388upx;
- white-space: nowrap;
- width: 100%;
- .zaiui-scroll-view-item {
- display: inline-block;
- width: 100%;
- .cu-list.grid {
- background-color: inherit;
- .grid-icon {
- margin: 0 30upx;
- .icon {
- border-radius: 100%;
- }
- }
- }
- .cu-list.grid>.cu-item text {
- color: #333333;
- }
- .cu-list.grid>.cu-item .cu-tag {
- transform: scale(0.8);
- }
- }
- }
- .zaiui-scroll-h-view {
- position: absolute;
- height: 10upx;
- bottom: 2upx;
- left: 0;
- right: 0;
- width: 32px;
- margin: auto;
- .box {
- position: relative;
- background: #d0cfcf;
- border-radius: 40upx;
- width: 100%;
- height: 100%;
- .dot {
- position: absolute;
- width: 16px;
- height: 100%;
- border-radius: 40upx;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- }
- }
- }
- }
- </style>
|