From a8e2f971ecaa34570f679ec6f33c9a48cf109f82 Mon Sep 17 00:00:00 2001 From: zxl <763096477@qq.com> Date: 星期五, 20 六月 2025 10:41:17 +0800 Subject: [PATCH] 导入组件代码清理 --- pages/userPermissions/userPermissions.vue | 200 ++++++++++++++++++++++++-------------------------- 1 files changed, 96 insertions(+), 104 deletions(-) diff --git a/pages/userPermissions/userPermissions.vue b/pages/userPermissions/userPermissions.vue index 1c2079f..7a4c50c 100644 --- a/pages/userPermissions/userPermissions.vue +++ b/pages/userPermissions/userPermissions.vue @@ -3,47 +3,52 @@ <!-- 鏍囬 --> <view class="header"> <text class="title">鐢ㄦ埛鍒楄〃</text> - </view> <view> - <button class="add-btn" @click="navigateToAdd()">鏂板鐢ㄦ埛</button> + <button class="add-btn" @click="navigateToAdd()" :disabled="!isShopkeeper">鏂板鐢ㄦ埛</button> </view> <!-- 鎼滅储妗� --> <view class="search-box"> - <u-search v-model="query.realName" placeholder="鎼滅储濮撳悕" :showAction="false" @change="searchUser()"></u-search> + <u-search v-model="query.realName" placeholder="鎼滅储濮撳悕" :showAction="false" @change="searchClerk()"></u-search> </view> <!-- 鐢ㄦ埛鍒楄〃 --> - <scroll-view scroll-y class="user-list" @scrolltolower="loadMore" v-if="userList.length > 0"> - <view class="user-item" v-for="(user, index) in userList" :key="user.id" > + <scroll-view scroll-y class="clerk-list" @scrolltolower="loadMore" v-if="clerkList.length > 0"> + <view class="clerk-item" v-for="(clerk, index) in clerkList" :key="clerk.id" > - <view class="user-info"> - <text class="realName">{{ user.realName }}</text> - <text class="mobile">{{ user.mobile }}</text> + <view class="clerk-info"> + <text class="realName">{{ clerk.realName ? clerk.realName: '鏈缃汉鍚�' }}</text> + <text class="mobile">{{ clerk.mobile }}</text> </view> <!-- 鎿嶄綔鎸夐挳鍖哄煙 --> <view class="action-buttons"> - <u-button type="primary" size="mini" @click.stop="restPassword(user.memberId)" class="edit-btn">閲嶇疆瀵嗙爜</u-button> - <u-button type="primary" size="mini" @click.stop="navigateToDetail(user.id)" class="edit-btn">淇敼</u-button> - <u-button type="error" size="mini" @click.stop="deleteUser(user.id)" - class="delete-btn">鍒犻櫎</u-button> - </view> + <u-button type="primary" size="mini" @click.stop="restPassword(clerk.memberId)" class="edit-btn" :disabled="!checkPermission(clerk)">閲嶇疆瀵嗙爜</u-button> + <u-button type="primary" size="mini" @click.stop="navigateToDetail(clerk.id)" class="edit-btn" :disabled="!checkPermission(clerk)">淇敼</u-button> + <u-button type="error" size="mini" @click.stop="deleteUser(clerk.id)" + class="delete-btn" :disabled="!checkPermission(clerk)">鍒犻櫎</u-button> + </view> </view> <!-- 鍔犺浇鏇村鎻愮ず --> - <view class="load-more" v-if="loading"> - <u-loading :show="loading"></u-loading> + + <view class="load-more"> + <u-loadmore + v-if="clerkList.length > 0" + :status="loading ? 'loading' : noMore ? 'nomore' : 'loadmore'" + :load-text="{ + loadmore: '涓婃媺鍔犺浇鏇村', + loading: '姝e湪鍔犺浇', + nomore: '娌℃湁鏇村浜�' + }" + /> </view> - <view class="load-more" v-if="noMoreData"> - <text>娌℃湁鏇村鏁版嵁浜�</text> + <view style="height:150rpx"> + </view> </scroll-view> - <!-- 绌虹姸鎬� --> - <view class="empty" v-else> - <text>鏆傛棤鐢ㄦ埛鏁版嵁</text> - </view> + </view> </template> @@ -53,41 +58,31 @@ del, add, update, - restPassword + restPassword, + checkClerkPermission } from "@/api/userPermissions.js" - import UIcon from '@/uview-components/uview-ui/components/u-icon/u-icon.vue'; - import UButton from '@/uview-components/uview-ui/components/u-button/u-button.vue'; - import UForm from '@/uview-components/uview-ui/components/u-form/u-form.vue'; - import UFormItem from '@/uview-components/uview-ui/components/u-form-item/u-form-item.vue'; - import UInput from '@/uview-components/uview-ui/components/u-input/u-input.vue'; - import USearch from '@/uview-components/uview-ui/components/u-search/u-search.vue'; - import UPopup from '@/uview-components/uview-ui/components/u-popup/u-popup.vue'; - import ULoading from '@/uview-components/uview-ui/components/u-loading/u-loading.vue' + import '@/components/uview-components/uview-ui'; - + import storage from "@/utils/storage.js"; //缂撳瓨 + import { + getUserInfo + } from "@/api/members"; + export default { - components: { - UIcon, - UButton, - UForm, - UFormItem, - UInput, - USearch, - UPopup, - ULoading - }, data() { return { - userList: [], // 鐢ㄦ埛鍒楄〃鏁版嵁 + total:0, + clerkList: [], // 鐢ㄦ埛鍒楄〃鏁版嵁 loading: false, // 鍔犺浇鐘舵�� - noMoreData: false, // 鏄惁娌℃湁鏇村鏁版嵁 + noMore: false, // 鏄惁娌℃湁鏇村鏁版嵁 query: { realName: '', - page: 1, - pageSize: 10, - } - - + pageNumber: 1, + pageSize: 15, + }, + isSuper:false, + isShopkeeper:false, + clerkId:'',//鐧诲綍璐﹀彿id } }, onShow() { @@ -95,8 +90,31 @@ }, onLoad() { this.getPage() + //鑾峰緱鐢ㄦ埛鏉冮檺 + checkClerkPermission().then(res=>{ + this.isSuper = res.data.data.isSuper; + this.isShopkeeper = res.data.data.isShopkeeper; + this.clerkId = res.data.data.clerkId; + }) + }, + methods: { + //妫�鏌ユ潈闄� + checkPermission(clerk){ + if(this.isShopkeeper){ + return true; + } + if(this.clerkId === clerk.id){ + return true; + }else{ + if(this.isSuper && !clerk.isSuper){ + return true; + } + return false; + } + + }, restPassword(id){ restPassword(id).then(res=>{ if(res.statusCode === 200){ @@ -116,14 +134,18 @@ getPage(this.query).then(res => { uni.hideLoading(); if (res.statusCode === 200) { - const data = res.data.data; - if (this.query.page === 1) { - this.userList = data || []; - } else { - // 鍚﹀垯杩藉姞鏁版嵁 - this.userList = [...this.userList, ...(data || [])]; - - } + const newData = res.data.data; + // 鏇存柊鎬绘暟鎹噺 + this.total = res.data.total || 0; + // 杩藉姞鎴栨浛鎹㈡暟鎹� + this.clerkList = this.query.pageNumber === 1 ? + newData : + [...this.clerkList, ...newData]; + + // 鍒ゆ柇鏄惁杩樻湁鏇村鏁版嵁 + this.noMore = newData.length < this.query.pageSize || + this.clerkList.length >= this.total; + } }) @@ -131,17 +153,17 @@ }, // 鎼滅储鐢ㄦ埛 - searchUser() { - this.query.page = 1 - this.noMoreData = false - this.userList = [] + searchClerk() { + this.query.pageNumber = 1 + this.noMore = false + this.clerkList = [] this.getPage() }, // 鍔犺浇鏇村 loadMore() { - if (!this.noMoreData) { - this.query.page++ + if (!this.noMore) { + this.query.pageNumber++ this.getPage() } }, @@ -163,26 +185,14 @@ this.getPage(); } }) - } + }, + + } } </script> <style lang="scss" scoped> - .user-item { - display: flex; - justify-content: space-between; - align-items: center; - padding: 20rpx; - border-bottom: 1rpx solid #f5f5f5; - } - - .user-info { - flex: 1; - display: flex; - flex-direction: column; - } - .action-buttons { display: flex; margin-left: 20rpx; @@ -232,12 +242,12 @@ margin-bottom: 20rpx; } - .user-list { + .clerk-list { flex: 1; overflow: hidden; } - .user-item { + .clerk-item { display: flex; align-items: center; padding: 20rpx; @@ -253,7 +263,7 @@ margin-right: 20rpx; } - .user-info { + .clerk-info { flex: 1; display: flex; flex-direction: column; @@ -270,30 +280,12 @@ } } } - .load-more { - padding: 20rpx; - text-align: center; - color: #999; - font-size: 28rpx; - } + padding: 20rpx 0; + text-align: center; + color: #999; + font-size: 26rpx; + background-color: #f7f8fa; + } - .empty { - flex: 1; - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - padding: 40rpx; - - image { - width: 200rpx; - margin-bottom: 20rpx; - } - - text { - color: #999; - font-size: 28rpx; - } - } </style> \ No newline at end of file -- Gitblit v1.8.0