天天看點

uni-app 7個人中心頁開發

my.nvue 内容如下
<template>
  <view class="page">
    <free-nav-bar bgColor="bg-white">
      <free-icon-button slot="right"><text class="iconfont font-md"></text></free-icon-button>
    </free-nav-bar>
    
    <free-list-item cover="../../../static/images/demo/demo6.jpg" title="呵呵" showRight coverSize="120">
      <view class="flex flex-column">
        <text class="text-dark font-lg font-weight-bold">呵呵</text>
        <text class="text-light-muted font-md">微信号:VmzhbjzhV</text>
      </view>
      <view slot="right">
        <text class="iconfont font-md text-light-muted"></text>
      </view>
    </free-list-item>
    
    <free-divider></free-divider>
    <free-list-item title="支付" showRight>
      <text slot="icon" class="iconfont font-lg py-1"></text>
    </free-list-item>
    
    <free-divider></free-divider>
    <free-list-item title="收藏" showRight>
      <text slot="icon" class="iconfont font-lg py-1"></text>
    </free-list-item>
    <free-list-item title="相冊" showRight>
      <text slot="icon" class="iconfont font-lg py-1"></text>
    </free-list-item>
    <free-list-item title="表情" showRight>
      <text slot="icon" class="iconfont font-lg py-1"></text>
    </free-list-item>
    <free-list-item title="設定" showRight>
      <text slot="icon" class="iconfont font-lg py-1"></text>
    </free-list-item>
  </view>
</template>

<script>
  import freeNavBar from "@/components/free-ui/free-nav-bar.vue";
  import freeIconButton from "@/components/free-ui/free-icon-button.vue";
  import freeListItem from "@/components/free-ui/free-list-item.vue";
  import freeDivider from "@/components/free-ui/free-divider.vue";
  export default {
    components:{
      freeNavBar,
      freeIconButton,
      freeListItem,
      freeDivider
    },
    data() {
      return {
        
      }
    },
    methods: {
      
    }
  }
</script>

<style>

</style>      
插件
free-list-item.vue
<template> 
  <view class="bg-white flex align-stretch" hover-class="bg-light" @click="$emit('click')">
    <view class="flex align-center justify-center py-2 px-3">
      <slot name="icon"></slot>
      <image :src="cover" v-if="cover" style="width: 75rpx;height: 75rpx;" mode="widthFix" :style="coverStyle"></image>
    </view>
    <view class="flex-1 border-bottom flex align-center justify-between">
      <slot>
        <text class="font-md text-dark">{{title}}</text>
      </slot>
      <view class="flex align-center pr-3" v-if="showRight">
        <slot name="right"></slot>
        <!-- 右 -->
        <text class="iconfont text-light-muted font-md" ></text>
      </view>
    </view>
  </view>
</template>

<script>
  export default{
    props:{
      // 封面
      cover:{
        type:String,
        default:""
      },
      // 标題
      title:{
        type:String,
        default:""
      },
      // 顯示右邊
      showRight:{
        type:Boolean,
        default:false
      },
      // 封面大小
      coverSize:{
        type:[String,Number],
        default:75
      }
    },
    computed:{
      coverStyle(){
        return `width:${this.coverSize}rpx;height:${this.coverSize}rpx;`;
      }
    }
  }
</script>

<style>
</style>      
free-nav-bar.vue
<template>
  <view>
    <view :class="getClass">
      <!-- 狀态欄 -->
      <view :style="'height:'+statusBarHeight+'px;'"></view>
      <!-- 導航 -->
      <view class="w-100 flex align-center justify-between" style="height: 90rpx;">
        <!-- 左邊 -->
        <view class="flex align-center">
          <!-- 标題 -->
          <text v-if="title" class="font-md ml-3" >{{getTitle}}</text>
        </view>
        <!-- 右邊 -->
        <view class="flex align-center">
          <slot name="right">
            <free-icon-button @click="search"><text class="iconfont font-md"></text></free-icon-button>
            <free-icon-button @click="openExtend"><text class="iconfont font-md"></text></free-icon-button>
          </slot>
        </view>
        <!--\ue6e3 \ue682 -->
      </view>
    </view>

    <!-- 站位 -->
    <view v-if="fixed" :style="fixedStyle"></view>
    
    <!-- 擴充菜單  -->
    <free-popup ref="extend" maskColor bottom :bodyWidth="320" :bodyHeight="525" bodyBgColor="bg-dark" transformOrigin="right top">
      <view class="flex flex-column" style="width:320rpx;height: 525rpx;">
          <view v-for="(item,index) in menus" :key="index" class="flex-1 flex align-center" hover-class="bg-hover-dark" @click="clickEvent(item.event)">
            <text class="pl-3 pr-2 iconfont font-md text-white">{{item.icon}}</text>
            <text class="font-md text-white">{{item.name}}</text>
          </view>
      </view>
    </free-popup>
  </view>
</template>

<script>
  import freeIconButton from './free-icon-button.vue';
  import freePopup from './free-popup.vue';
  export default {
    components: {
      freeIconButton,
      freePopup
    },
    props: {
      title: {
        type: String,
        default: ''
      },
      fixed:{
        type:Boolean,
        default:false
      },
      noreadnum:{
        type:Number,
        default:0
      },
      bgColor:{
        type:String,
        default:"bg-light"
      }
    },
    data() {
      return {
        statusBarHeight: 0,
        navBarHeight: 0,
        menus:[
          {
            name:'發起群聊',
            event:"",
            icon:"\ue633"
          },
          {
            name:'添加好友',
            event:"",
            icon:"\ue65d"
          },
          {
            name:'掃一掃',
            event:"",
            icon:"\ue614"
          },
          {
            name:'收付款',
            event:"",
            icon:"\ue66c"
          },
          {
            name:'幫助與回報',
            event:"",
            icon:"\ue61c"
          }
        ],
      }
    },
    mounted() {
      // 擷取工作列高度
      // #ifdef APP-PLUS-NVUE
      this.statusBarHeight = plus.navigator.getStatusbarHeight()
      // #endif
      this.navBarHeight = this.statusBarHeight + uni.upx2px(90)
    },
    computed: {
      fixedStyle() {
        return `height:${this.navBarHeight}px`;
      },
      getTitle(){
        let noreadnum = this.noreadnum>0 ? '('+this.noreadnum+')' : '';
        return this.title + noreadnum;
      },
      getClass(){
        let fixed = this.fixed?"fixed-top":"";
        return `${fixed} ${this.bgColor}`;
      }
    },
    methods:{
      openExtend(){
        this.$refs.extend.show(uni.upx2px(415),uni.upx2px(150));
      }
    }
  }
</script>

<style>

</style>      

free-icon-button.vue

<template>
  <view class="flex align-center justify-center" 
  hover-class="bg-hover-light" @click="$emit('click')"
  style="height: 90rpx;width: 90rpx;">
    <slot></slot>
  </view>
</template>

<script>
  export default {
    props: {
      icon: {
        type: String,
        default: ''
      },
    },
    mounted() {
      // #ifdef APP-PLUS-NVUE
      // 加載公共圖示庫
      const domModule = weex.requireModule('dom')
      domModule.addRule('fontFace', {
          'fontFamily': "iconfont",
          'src': "url('/static/font_1365296_2ijcbdrmsg.ttf')"
      });
      // #endif
    }
  }
</script>

<style>
</style>      
頁面是醬紫的
uni-app 7個人中心頁開發

繼續閱讀