uni-app 18个人资料设置开发

简介: uni-app 18个人资料设置开发

先看效果图

代码如下图所示

userinfo.nvue
<template>
  <view class="page">
    <!-- 导航栏 -->
    <free-nav-bar title="个人资料" showBack :showRight="false"></free-nav-bar>
    <free-list-item title="头像" showRight :showLeftIcon="false" @click="update('avatar')">
      <free-avatar slot="right" :src="avatar"></free-avatar>
    </free-list-item>
    <free-list-item title="昵称" showRight :showLeftIcon="false" @click="update('nickname')">
      <text slot="right" class="font text-muted">{{nickname}}</text>
    </free-list-item>
    <free-list-item title="账号" showRight :showLeftIcon="false"  @click="update('username')">
      <text slot="right" class="font text-muted">{{username}}</text>
    </free-list-item>
    <free-list-item title="二维码名片" showRight :showLeftIcon="false">
      <text slot="right" class="iconfont font-md">&#xe647;</text>
    </free-list-item>
    
    <free-confirm :title="confirmTitle" ref="confirm">
      <input type="text" class="border-bottom font-md" :placeholder="placeholder" v-model="confirmText"/>
    </free-confirm>
  </view>
</template>
<script>
  import freeNavBar from '@/components/free-ui/free-nav-bar.vue';
  import freeAvatar from '@/components/free-ui/free-avatar.vue';
  import freeListItem from '@/components/free-ui/free-list-item.vue';
  import freeConfirm from '@/components/free-ui/free-confirm.vue';
  export default {
    components:{
      freeNavBar,
      freeAvatar,
      freeListItem,
      freeConfirm
    },
    data() {
      return {
        avatar:'/static/images/demo/demo6.jpg',
        nickname:'昵称',
        username:'账号',
        confirmText:'',
        confirmType:'',
        user:[],
        inputtext:''
      }
    },
    computed:{
      confirmTitle(){
        return this.confirmType=='username' ? '修改账号' : '修改昵称';
      },
      placeholder(){
        return this.confirmType=='username' ? '输入账号' : '输入昵称';
      }
    },
    methods: {
      update(key){
        switch(key){
          case 'avatar':
            uni.chooseImage({
              count:1,
              sizeType:['compressed'],
              success:(res)=>{
                this.avatar = res.tempFilePaths[0];
              }
            })
          break;
          default:
          this.confirmType = key;
          // this.confirmText = this.user[key];
          if(key === 'nickname'){
            this.confirmText = this.nickname;
          }else{
            this.confirmText = this.username;
          }
          this.$refs.confirm.show((close)=>{
            if(this.confirmText===''){
              return uni.showToast({
                title:'不能为空',
                icon:'none'
              })
            }
            // this.user[key] = this.confirmText;
            if(key === 'nickname'){
              this.nickname = this.confirmText;
            }else{
              this.username = this.confirmText;
            }
            uni.showToast({
              title:'修改成功',
              icon:'none'
            });
            close();
          });
          break;
        }
      }
    }
  }
</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">
          <!-- 返回按钮 -->
          <free-icon-button v-if="showBack" @click="back"><text class="iconfont font-md">&#xe60d;</text></free-icon-button>
          <!-- 标题 -->
          <text v-if="title" class="font-md ml-3" >{{getTitle}}</text>
        </view>
        <!-- 右边 -->
        <view class="flex align-center" v-if="showRight">
          <slot name="right">
            <free-icon-button @click="search"><text class="iconfont font-md">&#xe6e3;</text></free-icon-button>
            <free-icon-button @click="openExtend"><text class="iconfont font-md">&#xe682;</text></free-icon-button>
          </slot>
        </view>
        <!--\ue6e3 \ue682 -->
      </view>
    </view>
    <!-- 站位 -->
    <view v-if="fixed" :style="fixedStyle"></view>
    
    <!-- 扩展菜单  -->
    <free-popup v-if="showRight" 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: {
      showBack:{
        type:Boolean,
        default:false
      },
      title: {
        type: String,
        default: ''
      },
      fixed:{
        type:Boolean,
        default:false
      },
      noreadnum:{
        type:Number,
        default:0
      },
      bgColor:{
        type:String,
        default:"bg-light"
      },
      showRight:{
        type:Boolean,
        default:true
      }
    },
    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));
      },
      // 返回
      back(){
        uni.navigateBack({
          delta:1
        })
      }
    }
  }
</script>
<style>
</style>
// free-avatar.vue
<template>
  <image :src="src" mode="widthFix" :style="getStyle" :class="type" :clickType="clickType" @click="clickEvent"></image>
</template>
<script>
  export default{
    props:{
      size:{
        type:[String,Number],
        default:90
      },
      src:{
        type:String,
        default:""
      },
      type:{
        type:String,
        default:"rounded"
      },
      clickType:{
        type:String,
        default:"none"
      }
    },
    computed:{
      getStyle(){
        return `width: ${this.size}rpx;height: ${this.size}rpx;`;
      }
    },
    methods:{
      clickEvent(){
        switch(this.clickType){
          case 'navigateTo':
          uni.navigateTo({
            url:'/pages/mail/user-base/user-base',
          });
          break;
          default:
          this.$emit('click');
          break;
        }
      }
    }
  }
</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 pl-3" v-if="showLeftIcon">
      <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 flex align-center justify-between py-3 pl-3" :class="border ? 'border-bottom' : ''">
      <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" v-if="showRightIcon" >&#xe60c;</text>
      </view>
    </view>
  </view>
</template>
<script>
  export default{
    props:{
      // 是否开启下边线
      border:{
        type:Boolean,
        default:true
      },
      // 封面
      cover:{
        type:String,
        default:""
      },
      // 标题
      title:{
        type:String,
        default:""
      },
      // 显示右边
      showRight:{
        type:Boolean,
        default:false
      },
      // 封面大小
      coverSize:{
        type:[String,Number],
        default:75
      },
      // 显示左边图标
      showLeftIcon:{
        type:Boolean,
        default:true
      },
      showRightIcon:{
        type:Boolean,
        default:true
      }
    },
    computed:{
      coverStyle(){
        return `width:${this.coverSize}rpx;height:${this.coverSize}rpx;`;
      }
    }
  }
</script>
<style>
</style>
// free-confirm.vue
<template>
  <free-popup ref="confirm" center maskColor transformOrigin='center'>
    <view class="bg-white rounded" style="width: 600rpx;">
      <!-- 头部 -->
      <view class="p-4 flex flex-column">
        <text class="font-md font-weight-bold mb-3">{{title}}</text>
        <slot></slot>
        <!-- <scroll-view scroll-x="true" class="flex" :show-scrollbar='false'>
          <view class="mr-1" v-for="i in 10" :key="i">
            <free-avatar src="/static/images/mail/friend.png" size="60"></free-avatar>
          </view>
        </scroll-view>
        <view class="my-3 bg-light rounded p-2">
          <text class="font text-light-muted">[个人名片] 昵称</text>
        </view>
        <input type="text" value="" class="border-bottom font-md" style="height: 60rpx;" placeholder="给朋友留言"  /> -->
      </view>
      <!-- 底部 -->
      <view style="height:100rpx;" class="flex border-top align-stretch">
        <view @click="cancel" class="flex-1 border-right align-center justify-center">
          <text class="font-md text-muted">取消</text>
        </view>
        <view @click="confirm"  class="flex-1 align-center justify-center">
          <text class="font-md main-text-color">确定</text>
        </view>
      </view>
    </view>
  </free-popup>
</template>
<script>
  import freePopup from '@/components/free-ui/free-popup.vue';
  export default{
    components:{
      freePopup
    },
    props:{
      title:{
        type:String,
        default:'提示:'
      }
    },
    data(){
      return {
        callback:false
      }
    },
    methods:{
      // 显示 
      show(callback=false){
        this.callback = callback;
        this.$refs.confirm.show();
      },
      // 取消
      cancel(){
        this.$refs.confirm.hide();
      },
      // 确定
      confirm(){
        if(typeof this.callback === 'function'){
          this.callback(()=>{
            this.cancel();
          });
        }
      }
    }
  }
</script>
<style>
</style>

感谢大家观看,我们下期见

目录
相关文章
|
23天前
|
移动开发 小程序
如何让uni-app开发的H5页面顶部原生标题和小程序的顶部标题不一致?
如何让uni-app开发的H5页面顶部原生标题和小程序的顶部标题不一致?
|
2月前
|
API 数据安全/隐私保护 iOS开发
利用uni-app 开发的iOS app 发布到App Store全流程
利用uni-app 开发的iOS app 发布到App Store全流程
95 3
|
2月前
|
Android开发 开发者 UED
个人开发 App 成功上架手机应用市场的关键步骤
个人开发 App 成功上架手机应用市场的关键步骤
|
2月前
|
开发工具 数据安全/隐私保护 Android开发
【教程】APP 开发后如何上架?
【教程】APP 开发后如何上架?
|
2月前
|
API
uni-app 146朋友圈列表api开发
uni-app 146朋友圈列表api开发
19 0
|
1天前
|
前端开发 Android开发 开发者
【Flutter前端技术开发专栏】Flutter中的混合应用(Hybrid Apps)开发
【4月更文挑战第30天】本文探讨了使用Flutter开发混合应用的方法。混合应用结合Web技术和原生容器,提供快速开发和低成本维护。Flutter,一款现代前端框架,以其插件系统和高性能渲染引擎支持混合应用开发。通过创建Flutter项目、添加平台代码、使用WebView、处理平台间通信以及发布应用,开发者可构建跨平台混合应用。虽然混合应用有性能和用户体验的局限,但Flutter的跨平台兼容性和丰富的插件生态降低了开发成本。开发者应根据项目需求权衡选择。
【Flutter前端技术开发专栏】Flutter中的混合应用(Hybrid Apps)开发
|
23天前
|
移动开发 小程序 前端开发
使用uni-app开发(h5、小程序、app)步骤
使用uni-app开发(h5、小程序、app)步骤
|
2月前
|
Java Android开发 开发者
【Uniapp开发】APP的真机调试指南,从开发到上架全过程
【Uniapp开发】APP的真机调试指南,从开发到上架全过程
36 3
游戏直播APP平台开发多少钱成本:定制与成品源码差距这么大
开发一款游戏直播APP平台所需的费用是多少?对于计划投身这一领域的投资者来说,首要关心的问题之一就是。本文将探讨两种主要的开发模式——定制开发与成品源码二次开发的成本差异及其优劣势。
|
2月前
|
开发框架 移动开发 JavaScript
SpringCloud微服务实战——搭建企业级开发框架(四十六):【移动开发】整合uni-app搭建移动端快速开发框架-环境搭建
正如优秀的软件设计一样,uni-app把一些移动端常用的功能做成了独立的服务或者插件,我们在使用的时候只需要选择使用即可。但是在使用这些服务或者插件时一定要区分其提供的各种服务和插件的使用场景,例如其提供的【uni-starter快速开发项目模版】几乎集成了移动端所需的所有基础功能,使用非常方便,但是其许可协议只允许对接其uniCloud的JS开发服务端,不允许对接自己的php、java等其他后台系统。
153 2