| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460 | <template>  <view    class="wyb-pagination-box"    :style="{      paddingLeft: padding + 'rpx',      paddingRight: padding + 'rpx',      '--hover': autoHover    }"  >    <view class="wyb-pagination-left" :style="{ opacity: currentPage === 1 ? 0.5 : 1 }">      <view        v-if="showFirst"        :class="'wyb-pagination-first-page-' + (showIcon ? 'i' : 't')"        :style="btnStyleStr"        :hover-class="currentPage === 1 ? '' : 'wyb-pagination-hover'"        @tap="onPageBtnTap('first-page')"      >        <view v-if="showIcon" class="iconfont icon-shuangjiantou left-arrow" />        <text v-else>{{ firstText }}</text>      </view>      <view        :class="'wyb-pagination-prev-page-' + (showIcon ? 'i' : 't')"        :style="btnStyleStr"        :hover-class="currentPage === 1 ? '' : 'wyb-pagination-hover'"        @tap="onPageBtnTap('prev-page')"      >        <view v-if="showIcon" class="iconfont icon-danjiantou left-arrow" />        <text v-else>{{ prevText }}</text>      </view>    </view>    <view class="wyb-pagination-info" @tap.stop="onInfoTap">      <view class="wyb-pagination-num" v-if="!infoClick">        <text :style="{ color: currentColor }">{{ currentPage }}</text>        <text class="wyb-pagination-span" :style="{ color: pageInfoColor }">/</text>        <text :style="{ color: pageInfoColor }">{{ totalPage }}</text>        <text v-if="showTotalItem" class="wyb-pagination-info-total" :style="{ color: RGBChange(pageInfoColor, 0.5, 'light') }">          ({{ totalItems }})        </text>      </view>      <!-- #ifndef MP-WEIXIN || APP-VUE || APP-NVUE || APP-PLUS || APP-PLUS-NVUE -->      <view class="wyb-pagination-input" v-else>        <input          type="number"          v-model="inputPage"          :onpaste="false"          :focus="infoFocus"          :value="currentPage"          :style="{ color: currentColor }"          :cursor-spacing="cursorSpacing"          @confirm="onInfoConfirm"          @blur="onInfoBlur"        />      </view>      <!-- #endif -->      <!-- #ifdef MP-WEIXIN || APP-VUE || APP-NVUE || APP-PLUS || APP-PLUS-NVUE -->      <view class="wyb-pagination-input" v-else>        <input          type="number"          v-model="inputPage"          :focus="infoFocus"          :name="currentPage"          :style="{ color: currentColor }"          :cursor-spacing="cursorSpacing"          @confirm="onInfoConfirm"          @blur="onInfoBlur"        />      </view>      <!-- #endif -->    </view>    <view class="wyb-pagination-right" :style="{ opacity: currentPage === totalPage ? 0.5 : 1 }">      <view        :class="'wyb-pagination-next-page-' + (showIcon ? 'i' : 't')"        :style="btnStyleStr"        :hover-class="currentPage === totalPage ? '' : 'wyb-pagination-hover'"        @tap="onPageBtnTap('next-page')"      >        <view v-if="showIcon" class="iconfont icon-danjiantou right-arrow" />        <text v-else>{{ nextText }}</text>      </view>      <view        v-if="showLast"        :class="'wyb-pagination-last-page-' + (showIcon ? 'i' : 't')"        :style="btnStyleStr"        :hover-class="currentPage === totalPage ? '' : 'wyb-pagination-hover'"        @tap="onPageBtnTap('last-page')"      >        <view v-if="showIcon" class="iconfont icon-shuangjiantou right-arrow" />        <text v-else>{{ lastText }}</text>      </view>    </view>  </view></template><script>export default {  data() {    return {      currentPage: this.current || 1,      inputPage: '',      infoClick: false,      infoFocus: false    };  },  computed: {    totalPage() {      return Math.ceil(parseFloat(this.totalItems) / parseFloat(this.pageItems));    },    autoHover() {      if (this.btnStyle.backgroundColor) {        return this.RGBChange(this.btnStyle.backgroundColor, 0.1, 'dark');      } else {        return this.RGBChange('#f8f8f8', 0.05, 'dark');      }    },    btnStyleStr() {      let styleStr = '';      for (let key in this.btnStyle) {        styleStr += `${this.sortFieldMatch(key)}: ${this.btnStyle[key]}; `;      }      return styleStr;    }  },  watch: {    current(val) {      const oPage = this.currentPage;      if (!Object.is(oPage, val)) {        this.currentPage = val;        this.$emit('change', {          type: 'prop-page',          current: this.currentPage        });      }    }  },  props: {    totalItems: {      type: [String, Number],      default: 20    },    pageItems: {      type: [String, Number],      default: 5    },    current: {      type: Number,      default: 1    },    prevText: {      type: String,      default: '上一页'    },    nextText: {      type: String,      default: '下一页'    },    firstText: {      type: String,      default: '首页'    },    lastText: {      type: String,      default: '尾页'    },    pageInfoColor: {      type: String,      default: '#494949'    },    currentColor: {      type: String,      default: '#007aff'    },    padding: {      type: [String, Number],      default: 15    },    btnStyle: {      type: Object,      default() {        return {};      }    },    showIcon: {      type: Boolean,      default: false    },    showTotalItem: {      type: Boolean,      default: false    },    showFirst: {      type: Boolean,      default: true    },    showLast: {      type: Boolean,      default: true    },    couldInput: {      type: Boolean,      default: true    },    cursorSpacing: {      type: Number,      default: 0    }  },  methods: {    onPageBtnTap(type) {      switch (type) {        case 'first-page':          if (!Object.is(this.currentPage, 1)) {            this.currentPage = 1;            this.$emit('change', { type, current: this.currentPage });          }          break;        case 'prev-page':          if (!Object.is(this.currentPage, 1)) {            this.currentPage--;            this.$emit('change', { type, current: this.currentPage });          }          break;        case 'next-page':          if (!Object.is(this.currentPage, this.totalPage)) {            this.currentPage++;            this.$emit('change', { type, current: this.currentPage });          }          break;        case 'last-page':          if (!Object.is(this.currentPage, this.totalPage)) {            this.currentPage = this.totalPage;            this.$emit('change', { type, current: this.currentPage });          }          break;      }    },    onInfoTap() {      if (this.couldInput) {        this.infoClick = true;        this.inputPage = this.currentPage;        setTimeout(() => {          this.infoFocus = true;        }, 10);      }    },    onInfoConfirm(e) {      let input = e.detail.value;      const oPage = this.currentPage;      if (parseFloat(input) > this.totalPage) {        this.currentPage = this.totalPage;      } else if (parseFloat(input) < 1) {        this.currentPage = 1;      } else if (input === '') {        this.currentPage = oPage;      } else {        this.currentPage = parseFloat(input);      }      if (!Object.is(oPage, this.currentPage)) {        this.$emit('change', {          type: 'input-page',          current: this.currentPage        });      }      this.infoClick = false;      this.$nextTick(() => {        this.infoFocus = false;      });    },    onInfoBlur(e) {      let input = e.detail.value;      const oPage = this.currentPage;      if (parseFloat(input) > this.totalPage) {        this.currentPage = this.totalPage;      } else if (parseFloat(input) < 1) {        this.currentPage = 1;      } else if (input === '') {        this.currentPage = oPage;      } else {        this.currentPage = parseFloat(input);      }      if (!Object.is(oPage, this.currentPage)) {        this.$emit('change', {          type: 'input-page',          current: this.currentPage        });      }      this.infoClick = false;      this.$nextTick(() => {        this.infoFocus = false;      });    },    RGBChange(color, level, type) {      // 判断颜色类型      let r = 0,        g = 0,        b = 0,        hasAlpha = false,        alpha = 1;      if (color.indexOf('#') !== -1) {        // hex转rgb        if (color.length === 4) {          let arr = color.split('');          color = '#' + arr[1] + arr[1] + arr[2] + arr[2] + arr[3] + arr[3];        }        let color16List = [color.substring(1, 3), color.substring(3, 5), color.substring(5, 7)];        r = parseInt(color16List[0], 16);        g = parseInt(color16List[1], 16);        b = parseInt(color16List[2], 16);      } else {        hasAlpha = color.indexOf('a') !== -1;        let root = color.slice();        let idx = root.indexOf('(') + 1;        root = root.substring(idx);        let firstDotIdx = root.indexOf(',');        r = parseFloat(root.substring(0, firstDotIdx));        root = root.substring(firstDotIdx + 1);        let secondDotIdx = root.indexOf(',');        g = parseFloat(root.substring(0, secondDotIdx));        root = root.substring(secondDotIdx + 1);        if (hasAlpha) {          let thirdDotIdx = root.indexOf(',');          b = parseFloat(root.substring(0, thirdDotIdx));          alpha = parseFloat(root.substring(thirdDotIdx + 1));        } else {          b = parseFloat(root);        }      }      let rgbc = [r, g, b];      // 减淡或加深      for (var i = 0; i < 3; i++)        type === 'light' ? (rgbc[i] = Math.floor((255 - rgbc[i]) * level + rgbc[i])) : (rgbc[i] = Math.floor(rgbc[i] * (1 - level)));      if (hasAlpha) {        return `rgba(${rgbc[0]}, ${rgbc[1]}, ${rgbc[2]}, ${alpha})`;      } else {        return `rgb(${rgbc[0]}, ${rgbc[1]}, ${rgbc[2]})`;      }    },    sortFieldMatch(field) {      const stringArray = field.split('');      let newField = field;      stringArray.forEach((t) => {        if (/[A-Z]/.test(t)) {          newField = field.replace(t, `-${t.toLowerCase()}`);        }      });      return newField;    }  }};</script><style>@import 'iconfont.css';.wyb-pagination-box {  width: 100%;  display: flex;  flex-direction: row;  align-items: center;  box-sizing: border-box;  justify-content: space-between;  flex-wrap: nowrap;}.wyb-pagination-left {  flex: 1;  display: flex;  flex-direction: row;  align-items: center;  flex-wrap: nowrap;  justify-content: flex-start;}.wyb-pagination-right {  flex: 1;  display: flex;  flex-direction: row;  align-items: center;  flex-wrap: nowrap;  justify-content: flex-end;}.wyb-pagination-first-page-t,.wyb-pagination-prev-page-t,.wyb-pagination-next-page-t,.wyb-pagination-last-page-t {  font-size: 27rpx;  padding: 14rpx 25rpx;  box-sizing: border-box;  background-color: #f8f8f8;  border: 1px solid #e5e5e5;  white-space: nowrap;}.wyb-pagination-first-page-i,.wyb-pagination-prev-page-i,.wyb-pagination-next-page-i,.wyb-pagination-last-page-i {  font-size: 27rpx;  padding: 14rpx 33rpx;  box-sizing: border-box;  background-color: #f8f8f8;  border: 1px solid #e5e5e5;  white-space: nowrap;}.wyb-pagination-first-page-t,.wyb-pagination-first-page-i {  margin-right: 15rpx;}.wyb-pagination-last-page-t,.wyb-pagination-last-page-i {  margin-left: 15rpx;}.wyb-pagination-info {  font-size: 33rpx;  white-space: nowrap;  display: flex;  flex-direction: row;  align-items: center;  justify-content: center;  flex: 1;}.wyb-pagination-input input {  text-align: center;}.wyb-pagination-span {  margin: 0 2rpx;}.wyb-pagination-info-total {  margin-left: 10rpx;}.wyb-pagination-first-page-t:active,.wyb-pagination-prev-page-t:active,.wyb-pagination-next-page-t:active,.wyb-pagination-last-page-t:active,.wyb-pagination-first-page-i:active,.wyb-pagination-prev-page-i:active,.wyb-pagination-next-page-i:active,.wyb-pagination-last-page-i:active {  background-color: var(--hover) !important;}.left-arrow {  transform: scale(0.9);  margin-right: 5rpx;}.right-arrow {  margin-left: 5rpx;  transform: scale(0.9) rotate(180deg);  -webkit-transform: scale(0.8) rotate(180deg);}</style>
 |