configuration.vue 3.2 KB
<template>
	<view class="configuation-page">
		<view class="configuation-header">
			<view class="header-gap"></view>
			<view class="search-top">
				<view class="search-main">
					<u--input @change="inputChanged" prefixIcon="search" placeholder="请输入组态名称" border="surround"
						shape="circle"></u--input>
				</view>
			</view>
		</view>
		<view style="height:35rpx"></view>
		<!-- 公共组件-每个页面必须引入 -->
		<public-module></public-module>
		<!-- 自带分页组件 -->
		<mescroll-body ref="mescrollRef" :up="upOption" @init="mescrollInit" :down="downOption" @down="downCallback"
			@up="upCallback">
			<view class="configuation-container">
				<view class="configuation-item">
					<view @click="openConfigDetail(item)" v-for="(item, index) in list" :key="index" class="item">
						<image class="image" :src="item.icon || defaultConfigImage"></image>
						<text class="name">{{ item.name }}</text>
					</view>
				</view>
			</view>
			<mescroll-empty v-if="!list.length" />
		</mescroll-body>
		<!-- 自带分页组件 -->
		<view style="height: 60rpx;"></view>
	</view>
</template>

<script>
	import MescrollMixin from '@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js';
	import api from '@/api/index.js'
	import {
		createScadaPageLink
	} from '../config/help.js';

	export default {
		mixins: [MescrollMixin], // 使用mixin (在main.js注册全局组件)
		data() {
			return {
				defaultConfigImage: '../../../../static/test.png',
				page: {
					num: 0,
					size: 10
				},
				downOption: {
					auto: true //是否在初始化后,自动执行downCallback; 默认true
				},
				upOption: {
					auto: false // 不自动加载
				},
				list: []
			};
		},
		onLoad() {
			// 隐藏原生的tabbar
			uni.hideTabBar();
			uni.setStorageSync('getConfiguration', {
				isConfiguration: false
			});
		},
		onUnload() {
			uni.setStorageSync('getConfiguration', {
				isConfiguration: false
			});
			uni.removeStorageSync('getConfiguration');
		},
		methods: {
			inputChanged(e) {
				this.page.num = 1;
				this.loadData(1, e);
			},
			openConfigDetail(e) {
				const href = createScadaPageLink(e)
				uni.navigateTo({
					url: 'configuration-detail?configurationHref=' + href
				});
			},
			/*下拉刷新的回调 */
			downCallback() {
				//联网加载数据
				this.page.num = 1;
				this.loadData(1);
			},
			/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
			upCallback() {
				//联网加载数据
				this.page.num += 1;
				this.loadData(this.page.num);
			},
			async loadData(pageNo, organizationV) {
				let httpData = {
					page: pageNo,
					pageSize: 10,
					name: organizationV,
					platform: 'phone',
					isTemplate:0
				};
				const res = await api.homeApi.getConfigurationApi({
					params: httpData,
					custom: {
						load: false
					}
				})
				if (res) {
					uni.stopPullDownRefresh();
					this.mescroll.endByPage(res.items.length, res.total);
					this.cameraTotal = res.total;
					if (pageNo == 1) {
						this.list = res.items;
					} else {
						this.list = this.list.concat(res.items);
					}
				}
			}
		}
	};
</script>

<style lang="scss" scoped>
	@import '../../static/configuration.scss';
</style>