uni-app 172标签列表和标签用户列表

Posted 2019ab

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了uni-app 172标签列表和标签用户列表相关的知识,希望对你有一定的参考价值。

app/router.js

  // 标签列表
  router.get('/tag/list',controller.tag.list);
  // 标签用户列表
  router.get('/tag/read/:id',controller.tag.read);

app/controller/group.js

'use strict';

const Controller = require('egg').Controller;

class TagController extends Controller 
    // 标签列表
    async list() 
        const  ctx, app  = this;
        let current_user_id = ctx.authUser.id;

        let rows = await app.model.Tag.findAll(
            where: 
                user_id: current_user_id
            ,
            attributes: ['id', 'name']
        );

        ctx.apiSuccess(rows);
    

    // 标签用户列表
    async read() 
        const  ctx, app  = this;
        let current_user_id = ctx.authUser.id;

        let id = parseInt(ctx.params.id);

        let rows = await app.model.Tag.findOne(
            where: 
                user_id: current_user_id,
                id
            ,
            attributes: ['id', 'name'],
            include: [
                model: app.model.Friend,
                attributes: ['nickname'],
                where: 
                    isblack: 0
                ,
                include: [
                    model: app.model.User,
                    as: "friendInfo",
                    attributes: ['id', 'nickname', 'avatar', 'username']
                ]
            ]
        );

        ctx.apiSuccess(rows.friends);

    



module.exports = TagController;

/pages/mail/tag-read/tag-read.vue

<template>
	<view class="page">
		<!-- 导航栏 -->
		<free-nav-bar title="标签列表" showBack :showRight="false">
		</free-nav-bar>
		
		<free-list-item v-for="(item,index) in list" :key="index" :title="item.name" :cover="item.avatar || '/static/images/userpic.png'"  @click="handle(item)" :showRight="true" :showRightIcon="true">
		</free-list-item>
		
	</view>
</template>

<script>
	import freeNavBar from '@/components/free-ui/free-nav-bar.vue';
	import freeListItem from '@/components/free-ui/free-list-item.vue';
	import $H from '@/common/free-lib/request.js';
	import auth from '@/common/mixin/auth.js';
	import  mapState  from 'vuex';
	export default 
		mixins:[auth],
		components: 
			freeNavBar,
			freeListItem
		,
		computed:
			
		,
		data() 
			return 
				id:0,
				list:[],
			
		,
		// 监听下拉刷新
		onPullDownRefresh() 
			this.getData().then(res=>
				uni.showToast(
						title:'刷新成功',
						icon:'none'
				);
				uni.stopPullDownRefresh();
			)
		,
		onLoad(e) 
			this.id = e.id;
			this.getData();
		,
		
		methods: 
			getData()
				return new Promise((result,reject)=>
					$H.get('/tag/read/'+this.id).then(res=>
						this.list = res.map(item=>
							return 
								id:item.friendInfo.id,
								name:item.nickname || item.friendInfo.nickname || item.friendInfo.username,
								avatar:item.friendInfo.avatar,
							
						)
						result(res);
					)
				);
				
			,
			handle(item)
				uni.navigateTo(
					url:'../user-base/user-base?user_id='+item.id,
				)
			
		
	
</script>

<style>

</style>

/pages/mail/tag-list/tag-list.vue

<template>
	<view class="page">
		<!-- 导航栏 -->
		<free-nav-bar title="标签列表" showBack :showRight="false">
		</free-nav-bar>
		
		<free-list-item v-for="(item,index) in list" :key="index" :title="item.name"  @click="handle(item)" :showRight="true" :showRightIcon="true">
		</free-list-item>
		
	</view>
</template>

<script>
	import freeNavBar from '@/components/free-ui/free-nav-bar.vue';
	import freeListItem from '@/components/free-ui/free-list-item.vue';
	import $H from '@/common/free-lib/request.js';
	import auth from '@/common/mixin/auth.js';
	import  mapState  from 'vuex';
	export default 
		mixins:[auth],
		components: 
			freeNavBar,
			freeListItem
		,
		computed:
			
		,
		data() 
			return 
				form:
					friend_id:0,
					nickname:"",
					lookme:1,
					lookhim:1
				,
				list:[],
			
		,
		// 监听下拉刷新
		onPullDownRefresh() 
			this.getData().then(res=>
				uni.showToast(
						title:'刷新成功',
						icon:'none'
				);
				uni.stopPullDownRefresh();
			)
		,
		onLoad(e) 
			this.getData();
		,
		
		methods: 
			getData()
				return new Promise((result,reject)=>
					$H.get('/tag/list').then(res=>
						this.list = res
						result(res);
					)
				);
				
			,
			handle(item)
				uni.navigateTo(
					url:'../tag-read/tag-read?id='+item.id
				);
			
		
	
</script>

<style>

</style>

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

以上是关于uni-app 172标签列表和标签用户列表的主要内容,如果未能解决你的问题,请参考以下文章

uni-app中常用的标签和样式

uni-app的view和text标签

uni-app.03.初始化picker下拉列表的默认值

uni-app 11设置备注和标签页

uni-app 147我的朋友圈列表api开发

uni-app 75聊天类封装-更新会话列表