添加全局私有视角到我的页面
This commit is contained in:
parent
a74badc79a
commit
9413b651e0
|
|
@ -3,7 +3,7 @@
|
|||
<!-- 顶部标题栏 -->
|
||||
<view class="header">
|
||||
<text class="header-title">客户管理</text>
|
||||
<view v-if="useUserStore().getUserInfo?.roles?.some(r => ['admin','sys_admin'].includes(r))" style="display: flex;align-items: center;gap: 6px">
|
||||
<view v-if="showPrivateSwitch" style="display: flex;align-items: center;gap: 6px">
|
||||
<view>私有</view><uv-switch v-model="filterSelf"></uv-switch>
|
||||
</view>
|
||||
|
||||
|
|
@ -161,6 +161,7 @@
|
|||
|
||||
<script setup>
|
||||
import { ref, computed, onMounted, onUnmounted, watch } from 'vue';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import FabPlus from '@/components/FabPlus.vue';
|
||||
import CustomerSummaryBrief from '@/components/customer/CustomerSummaryBrief.vue';
|
||||
import { usePagination } from '@/composables/usePagination';
|
||||
|
|
@ -171,7 +172,18 @@ import {
|
|||
} from '@/utils/customerMappings';
|
||||
|
||||
// 筛选状态
|
||||
const filterSelf =ref(false);
|
||||
const userStore = useUserStore();
|
||||
const { userInfo, privateView } = storeToRefs(userStore);
|
||||
const filterSelf = computed({
|
||||
get: () => privateView.value,
|
||||
set: (val) => userStore.setPrivateView(val)
|
||||
});
|
||||
const currentUserId = computed(() =>
|
||||
userInfo.value?.user?.userId || userInfo.value?.userId || null
|
||||
);
|
||||
const showPrivateSwitch = computed(() =>
|
||||
userInfo.value?.roles?.some(r => ['admin','sys_admin'].includes(r))
|
||||
);
|
||||
const showFilter = ref(false);
|
||||
const filterStatus = ref('');
|
||||
|
||||
|
|
@ -230,10 +242,10 @@ const formatDateTime = (dateTime) => {
|
|||
|
||||
// 构建查询参数(包含筛选条件)
|
||||
const buildQueryParams = () => {
|
||||
const params = {};
|
||||
|
||||
params.joinUserId = filterSelf.value? useUserStore().getUserInfo.user.userId : null
|
||||
console.log(filterSelf.value? useUserStore().getUserInfo.user.userId : null)
|
||||
const params = {
|
||||
joinUserId: filterSelf.value && currentUserId.value ? currentUserId.value : null
|
||||
};
|
||||
console.log(filterSelf.value ? currentUserId.value : null)
|
||||
|
||||
|
||||
// 只有有效的筛选状态才添加statusList参数
|
||||
|
|
@ -373,8 +385,8 @@ watch(filterStatus, () => {
|
|||
// 重置分页状态
|
||||
reset();
|
||||
// 清除所有查询参数,只保留基础分页参数,保留用户id过滤参数
|
||||
queryParams.value = {
|
||||
joinUserId: filterSelf.value? useUserStore().getUserInfo.user.userId : null,
|
||||
queryParams.value = {
|
||||
joinUserId: filterSelf.value && currentUserId.value ? currentUserId.value : null,
|
||||
pageNum: 1,
|
||||
pageSize: 10
|
||||
};
|
||||
|
|
@ -390,7 +402,7 @@ watch(filterStatus, () => {
|
|||
watch(filterSelf, () => {
|
||||
console.log('筛选是否自己变化:', filterSelf.value);
|
||||
const params = buildQueryParams();
|
||||
console.log('<UNK>:当前参数', params);
|
||||
console.log('客户列表查询参数', params);
|
||||
updateParams(params);
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -8,13 +8,7 @@
|
|||
|
||||
|
||||
<view class="dashboard-content" v-else>
|
||||
<view
|
||||
v-if="showPrivateSwitch"
|
||||
class="private-filter"
|
||||
>
|
||||
<view>私有</view>
|
||||
<uv-switch v-model="filterSelf"></uv-switch>
|
||||
</view>
|
||||
|
||||
<!-- 任务概览 -->
|
||||
<view class="task-overview">
|
||||
<view
|
||||
|
|
@ -160,15 +154,20 @@
|
|||
|
||||
<script setup>
|
||||
import { ref, onMounted, watch, computed } from 'vue';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { getTaskStatusType, getTaskStatusStyle, getStatusText } from '@/utils/taskConfig.js';
|
||||
import { getDashboardBrief, getTaskList } from '@/api';
|
||||
import { useUserStore } from '@/store/user';
|
||||
import {truncateText} from "@/utils/textSolve/truncateText";
|
||||
|
||||
const userStore = useUserStore();
|
||||
const filterSelf = ref(false);
|
||||
const showPrivateSwitch = computed(() =>
|
||||
userStore.getUserInfo?.roles?.some(r => ['admin', 'sys_admin'].includes(r))
|
||||
const { userInfo, privateView } = storeToRefs(userStore);
|
||||
const filterSelf = computed({
|
||||
get: () => privateView.value,
|
||||
set: (val) => userStore.setPrivateView(val)
|
||||
});
|
||||
const currentUserId = computed(() =>
|
||||
userInfo.value?.user?.userId || userInfo.value?.userId || null
|
||||
);
|
||||
|
||||
// 任务统计
|
||||
|
|
@ -339,9 +338,8 @@ const loadDashboardData = async () => {
|
|||
keys
|
||||
};
|
||||
|
||||
if (filterSelf.value) {
|
||||
const joinUserId = userStore.userInfo?.user?.userId;
|
||||
params.joinUserId = joinUserId;
|
||||
if (filterSelf.value && currentUserId.value) {
|
||||
params.joinUserId = currentUserId.value;
|
||||
}
|
||||
|
||||
const res = await getDashboardBrief(params);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,16 @@
|
|||
<template>
|
||||
<view class="mine-page">
|
||||
<view
|
||||
class="card settings-card"
|
||||
v-if="showPrivateSwitch"
|
||||
>
|
||||
<view class="setting-row">
|
||||
<text class="setting-label">私有视角</text>
|
||||
<uv-switch v-model="filterSelf" />
|
||||
</view>
|
||||
<text class="setting-desc">开启后仅展示分配给我的客户和任务数据</text>
|
||||
</view>
|
||||
|
||||
<view class="card">
|
||||
|
||||
<uv-button type="error" :plain="true" @click="onLogout" :loading="loading">
|
||||
|
|
@ -10,12 +21,21 @@
|
|||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
import { ref, computed } from 'vue'
|
||||
import { storeToRefs } from 'pinia'
|
||||
import { useUserStore } from '@/store/user'
|
||||
import { logout } from '@/api/user'
|
||||
|
||||
const loading = ref(false)
|
||||
const userStore = useUserStore()
|
||||
const { privateView, userInfo } = storeToRefs(userStore)
|
||||
const filterSelf = computed({
|
||||
get: () => privateView.value,
|
||||
set: (val) => userStore.setPrivateView(val)
|
||||
})
|
||||
const showPrivateSwitch = computed(() =>
|
||||
userInfo.value?.roles?.some(r => ['admin', 'sys_admin'].includes(r))
|
||||
)
|
||||
|
||||
const onLogout = async () => {
|
||||
if (loading.value) return
|
||||
|
|
@ -50,6 +70,28 @@ const onLogout = async () => {
|
|||
box-shadow: 0 6rpx 20rpx rgba(0, 0, 0, 0.04);
|
||||
}
|
||||
|
||||
.settings-card {
|
||||
margin-bottom: 24rpx;
|
||||
}
|
||||
|
||||
.setting-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.setting-label {
|
||||
font-size: 30rpx;
|
||||
font-weight: 500;
|
||||
color: #111827;
|
||||
}
|
||||
|
||||
.setting-desc {
|
||||
margin-top: 14rpx;
|
||||
font-size: 24rpx;
|
||||
color: #6b7280;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 30rpx;
|
||||
font-weight: 600;
|
||||
|
|
|
|||
|
|
@ -6,13 +6,24 @@ import { defineStore } from 'pinia'
|
|||
*/
|
||||
export const useUserStore = defineStore('user', {
|
||||
state: () => {
|
||||
const storedPrivateView = uni.getStorageSync('privateView')
|
||||
const normalizePrivateView = () => {
|
||||
if (typeof storedPrivateView === 'boolean') return storedPrivateView
|
||||
if (storedPrivateView === '' || storedPrivateView === undefined || storedPrivateView === null) {
|
||||
return false
|
||||
}
|
||||
return !!storedPrivateView
|
||||
}
|
||||
|
||||
return {
|
||||
// 用户 token
|
||||
token: uni.getStorageSync('token') || '',
|
||||
// 用户信息
|
||||
userInfo: uni.getStorageSync('userInfo') || null,
|
||||
// token 过期时间(可选)
|
||||
tokenExpireTime: uni.getStorageSync('tokenExpireTime') || null
|
||||
tokenExpireTime: uni.getStorageSync('tokenExpireTime') || null,
|
||||
// 是否启用私有视角
|
||||
privateView: normalizePrivateView()
|
||||
}
|
||||
},
|
||||
|
||||
|
|
@ -38,6 +49,13 @@ export const useUserStore = defineStore('user', {
|
|||
return state.userInfo
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取私有视角设置
|
||||
*/
|
||||
getPrivateView: (state) => {
|
||||
return state.privateView
|
||||
},
|
||||
|
||||
/**
|
||||
* 判断 token 是否过期(如果设置了过期时间)
|
||||
*/
|
||||
|
|
@ -93,11 +111,13 @@ export const useUserStore = defineStore('user', {
|
|||
this.token = ''
|
||||
this.userInfo = null
|
||||
this.tokenExpireTime = null
|
||||
this.privateView = false
|
||||
|
||||
// 清除本地存储
|
||||
uni.removeStorageSync('token')
|
||||
uni.removeStorageSync('userInfo')
|
||||
uni.removeStorageSync('tokenExpireTime')
|
||||
uni.removeStorageSync('privateView')
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -107,6 +127,15 @@ export const useUserStore = defineStore('user', {
|
|||
*/
|
||||
updateToken(token, expireTime = null) {
|
||||
this.setToken(token, expireTime)
|
||||
},
|
||||
|
||||
/**
|
||||
* 设置私有视角
|
||||
* @param {boolean} value
|
||||
*/
|
||||
setPrivateView(value) {
|
||||
this.privateView = value
|
||||
uni.setStorageSync('privateView', value)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user