fix: 主子账号功能完善。

This commit is contained in:
tianyongbao
2026-01-20 11:51:02 +08:00
parent b85b7ee550
commit 7a4ad91efa
7 changed files with 101 additions and 33 deletions

View File

@@ -32,7 +32,6 @@ const API_PATHS = {
AUTH: {
// 短信登录
LOGIN_SMS: {
v1: '/auth/login',
v2: '/auth/login',
},
// 获取短信验证码
@@ -41,7 +40,6 @@ const API_PATHS = {
},
// 微信手机号登录
LOGIN_WECHAT: {
v1: '/api/login/use_wechat',
v2: '/auth/wechat_login',
},
// 登出

View File

@@ -1,6 +1,7 @@
import httpService from '@/utils/request'
import API from './config'
import Taro from '@tarojs/taro'
import { useRootUserStore } from '@/store/index'
/** 设备相关接口---------------------------------------- */
// 设备列表
@@ -9,12 +10,14 @@ export function allDeviceList(params) {
}
// 设备详情
export function deviceInfo(data){
const userId = Taro.getStorageSync('UserId');
const store = useRootUserStore();
const userId = store.getRootUserId || Taro.getStorageSync('UserId');
return httpService.post(`${API.DEVICE.INFO()}?rootUserId=${userId}`, {data})
}
// 解除绑定
export function deviceUnbind(data){
const userId = Taro.getStorageSync('UserId');
const store = useRootUserStore();
const userId = store.getRootUserId || Taro.getStorageSync('UserId');
return httpService.post(`${API.DEVICE.UNBIND()}?rootUserId=${userId}`, {data})
}
// 将设备及开关绑定到塘口
@@ -27,13 +30,15 @@ export function deviceHistory(params){
}
// 修改设备名称
export function deviceUpdateName(data){
const userId = Taro.getStorageSync('UserId');
const store = useRootUserStore();
const userId = store.getRootUserId || Taro.getStorageSync('UserId');
return httpService.put(`${API.DEVICE.UPDATE_NAME()}?rootUserId=${userId}`, {data})
}
// 修改设备关联塘口
export function deviceUpdatePond(data){
const userId = Taro.getStorageSync('UserId');
return httpService.put(`${API.DEVICE.UPDATE_POND()}?rootUserId=${userId}`, {data})
const store = useRootUserStore();
const userId = store.getRootUserId || Taro.getStorageSync('UserId');
return httpService.put(`${API.DEVICE.UPDATE_POND()}?rootUserId=${userId}`, {data})
}
// 修改设备接电方式
export function deviceUpdateV(data){
@@ -67,17 +72,20 @@ export function addDeviceDetector(data) {
}
// 设置溶解氧/水温告警
export function setWarnCall(data){
const userId = Taro.getStorageSync('UserId');
const store = useRootUserStore();
const userId = store.getRootUserId || Taro.getStorageSync('UserId');
return httpService.post(`${API.DEVICE.SET_WARN_CALL()}?rootUserId=${userId}`, {data})
}
// 设置溶解氧上下限
export function setOxyWarn(data){
const userId = Taro.getStorageSync('UserId');
const store = useRootUserStore();
const userId = store.getRootUserId || Taro.getStorageSync('UserId');
return httpService.put(`${API.DEVICE.SET_OXY_WARN()}?rootUserId=${userId}`, {data})
}
// 设置温度上下限
export function setTempWarn(data){
const userId = Taro.getStorageSync('UserId');
const store = useRootUserStore();
const userId = store.getRootUserId || Taro.getStorageSync('UserId');
return httpService.put(`${API.DEVICE.SET_TEMP_WARN()}?rootUserId=${userId}`, {data})
}
// 溶解氧饱和度
@@ -91,7 +99,8 @@ export function addDeviceController(data) {
}
// 启停溶解氧
export function setOxyOpen(data){
const userId = Taro.getStorageSync('UserId');
const store = useRootUserStore();
const userId = store.getRootUserId || Taro.getStorageSync('UserId');
return httpService.put(`${API.DEVICE.SET_OXY_OPEN()}?rootUserId=${userId}`, {data})
}
/** 联动控制------------------------------------- */
@@ -109,7 +118,8 @@ export function updateLinkerCtrl(data){
}
// 删除联动控制
export function delLinkerCtrl(data){
const userId = Taro.getStorageSync('UserId');
const store = useRootUserStore();
const userId = store.getRootUserId || Taro.getStorageSync('UserId');
// 后端需要 /{ids} 路径参数
return httpService.delete(`${API.LINKED_CTRL.DELETE()}/${data.id}?rootUserId=${userId}`)
}
@@ -149,7 +159,8 @@ export function turnPondSwitch(data){
// 电压告警开关 开启或关闭
export function voltageCheckOpen(data){
const userId = Taro.getStorageSync('UserId');
const store = useRootUserStore();
const userId = store.getRootUserId || Taro.getStorageSync('UserId');
return httpService.put(`${API.DEVICE.VOLTAGE_CHECK()}?rootUserId=${userId}`, {data})
}
// 电流告警开关 开启或关闭

View File

@@ -1,10 +1,12 @@
import httpService from '@/utils/request'
import API from './config'
import Taro from '@tarojs/taro';
import { useRootUserStore } from '@/store/index';
// 塘口模式1
export function getPond1() {
const userId = Taro.getStorageSync("UserId");
const store = useRootUserStore();
const userId = store.getRootUserId || Taro.getStorageSync("UserId");
return httpService.get(API.HOME.POND_LIST(), {
params: {
rootUserId: userId || undefined
@@ -14,7 +16,8 @@ export function getPond1() {
// 塘口模式2
export function getPond2(){
const userId = Taro.getStorageSync("UserId");
const store = useRootUserStore();
const userId = store.getRootUserId || Taro.getStorageSync("UserId");
return httpService.get(API.HOME.POND_LIST_MODE2(), {
params: {
rootUserId: userId || undefined
@@ -29,8 +32,9 @@ export function noticeList(){
// 即将到期设备列表
export function deviceDead(){
const userId = Taro.getStorageSync("UserId");
return httpService.get(API.HOME.DEVICE_DEAD(), {
const store = useRootUserStore();
const userId = store.getRootUserId || Taro.getStorageSync("UserId");
return httpService.get(API.HOME.DEVICE_DEAD(), {
params: {
rootUserId: userId || undefined
}

View File

@@ -8,7 +8,7 @@ export function list_user_child() {
// 添加
export function add_user_child(mobilePhone) {
return httpService.post(API.SUB_ACCOUNT.ADD(), { mobilePhone })
return httpService.post(API.SUB_ACCOUNT.ADD(), { data: { mobilePhone } })
}
// 删除

View File

@@ -1,12 +1,15 @@
<template>
<view :style="{ height: statusBarHeight + 'px' }"></view>
<view class="nav-bar" :style="{ height: navBarHeight + 'px' }">
<view class="font_32 f_weight" @click="toParent"> {{ username }}的鱼塘</view>
<TriangleDown
color="#222"
@click="toParent"
v-if="parentList.length > 1"
></TriangleDown>
<view class="account-selector" @click="toParent">
<text class="account-prefix">账号选择</text>
<text class="account-name">{{ username }}的鱼塘</text>
<text class="account-type">{{ accountType }}</text>
<TriangleDown
color="#222"
v-if="parentList.length > 1"
></TriangleDown>
</view>
</view>
<!-- 选择塘口 -->
<nut-popup v-model:visible="showParent" position="bottom">
@@ -37,6 +40,16 @@ const navBarHeight = ref();
const username = ref(
Taro.getStorageSync("UserName") ? Taro.getStorageSync("UserName") : "鱼测云"
);
// 计算账号类型:主账号或子账号
const accountType = computed(() => {
const currentUserId = store.getRootUserId;
const originalUserId = Taro.getStorageSync("UserId");
if (currentUserId === originalUserId) {
return "(主账号)";
} else {
return "(子账号)";
}
});
//然后计算出navBarHeight
navBarHeight.value =
menuButtonInfo.bottom -
@@ -61,7 +74,7 @@ watchEffect(() => {
/** --------------method start------------------- */
function getParentList() {
list_user_parent().then((res: any) => {
if (res.statusCode == 200) {
if (res.code == 200) {
const arr = [
{
userId: Taro.getStorageSync("UserId"),
@@ -112,8 +125,43 @@ defineExpose({
display: flex;
align-items: center;
padding: 0 0 0 30px;
// position: fixed;
// z-index: 1000;
.account-selector {
display: flex;
align-items: center;
background: #f5f6f7;
border-radius: 8px;
padding: 8px 12px;
cursor: pointer;
transition: all 0.2s ease;
&:active {
background: #e8e9ea;
}
.account-prefix {
font-size: 28px;
color: #666;
font-weight: 500;
white-space: nowrap;
}
.account-name {
font-size: 28px;
color: #222;
font-weight: 600;
white-space: nowrap;
margin: 0 4px;
}
.account-type {
font-size: 24px;
color: #999;
white-space: nowrap;
margin-right: 4px;
}
}
.title {
margin-right: 20px;
}

View File

@@ -149,7 +149,7 @@ Taro.useDidShow(() => {
// 获取子账号列表
function getAccountList() {
list_user_child().then((res: any) => {
if (res.statusCode == 200) {
if (res.code == 200) {
accountList.value = res.data;
}
});
@@ -171,7 +171,7 @@ function del(id) {
success: function (res) {
if (res.confirm) {
delete_user_child(id).then((res: any) => {
if (res.statusCode == 200) {
if (res.code == 200) {
state.show = true;
state.msg = "删除成功";
getAccountList();
@@ -198,7 +198,7 @@ function submit() {
return;
}
add_user_child(Number(account.value)).then((res) => {
if (res.statusCode == 200) {
if (res.code == 200) {
state.show = true;
state.msg = "添加成功";

View File

@@ -39,10 +39,17 @@ export const BASE_URL = getBaseUrl()
const reg = /http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/;
let modalShown = false;
let timeModal = false;
// 需要loading的url
// 需要loading的url使用v2新版本接口
const urlLoadings = [
"/api/device/delete", "/api/device/set_controller_oxy_open", "/api/device/set_oxy_warn_call",
"/api/device-switch/turn_switch", "/api/device-switch/turn_pond_switch", "/api/device/voltage_check_open", "/api/device-switch/electric_check_open","/api/device-switch/electric_set"]
"/fishery/device", // 删除设备
"/fishery/device/set_controller_oxy_open", // 设置溶解氧机开关
"/fishery/device/set_oxy_warn_call", // 设置溶解氧告警
"/iot/switch/turn_switch", // 单个开关启停
"/iot/switch/turn_pond_switch", // 所有开关启停(全开/全关)
"/fishery/device/voltage_check_open", // 电压告警检测
"/fishery/deviceSwitch/electric_check_open",// 电流告警检测
"/iot/switch/electric_set" // 电流设置
]
let isShow = 0
const request = async (method, url, params) => {
const pattern = new RegExp(url.split("?rootuserid")[0], 'i');