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

View File

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

View File

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

View File

@@ -8,7 +8,7 @@ export function list_user_child() {
// 添加 // 添加
export function add_user_child(mobilePhone) { 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,13 +1,16 @@
<template> <template>
<view :style="{ height: statusBarHeight + 'px' }"></view> <view :style="{ height: statusBarHeight + 'px' }"></view>
<view class="nav-bar" :style="{ height: navBarHeight + 'px' }"> <view class="nav-bar" :style="{ height: navBarHeight + 'px' }">
<view class="font_32 f_weight" @click="toParent"> {{ username }}的鱼塘</view> <view class="account-selector" @click="toParent">
<text class="account-prefix">账号选择</text>
<text class="account-name">{{ username }}的鱼塘</text>
<text class="account-type">{{ accountType }}</text>
<TriangleDown <TriangleDown
color="#222" color="#222"
@click="toParent"
v-if="parentList.length > 1" v-if="parentList.length > 1"
></TriangleDown> ></TriangleDown>
</view> </view>
</view>
<!-- 选择塘口 --> <!-- 选择塘口 -->
<nut-popup v-model:visible="showParent" position="bottom"> <nut-popup v-model:visible="showParent" position="bottom">
<nut-picker <nut-picker
@@ -37,6 +40,16 @@ const navBarHeight = ref();
const username = ref( const username = ref(
Taro.getStorageSync("UserName") ? Taro.getStorageSync("UserName") : "鱼测云" 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
navBarHeight.value = navBarHeight.value =
menuButtonInfo.bottom - menuButtonInfo.bottom -
@@ -61,7 +74,7 @@ watchEffect(() => {
/** --------------method start------------------- */ /** --------------method start------------------- */
function getParentList() { function getParentList() {
list_user_parent().then((res: any) => { list_user_parent().then((res: any) => {
if (res.statusCode == 200) { if (res.code == 200) {
const arr = [ const arr = [
{ {
userId: Taro.getStorageSync("UserId"), userId: Taro.getStorageSync("UserId"),
@@ -112,8 +125,43 @@ defineExpose({
display: flex; display: flex;
align-items: center; align-items: center;
padding: 0 0 0 30px; 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 { .title {
margin-right: 20px; margin-right: 20px;
} }

View File

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

View File

@@ -39,10 +39,17 @@ export const BASE_URL = getBaseUrl()
const reg = /http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/; const reg = /http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/;
let modalShown = false; let modalShown = false;
let timeModal = false; let timeModal = false;
// 需要loading的url // 需要loading的url使用v2新版本接口
const urlLoadings = [ const urlLoadings = [
"/api/device/delete", "/api/device/set_controller_oxy_open", "/api/device/set_oxy_warn_call", "/fishery/device", // 删除设备
"/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/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 let isShow = 0
const request = async (method, url, params) => { const request = async (method, url, params) => {
const pattern = new RegExp(url.split("?rootuserid")[0], 'i'); const pattern = new RegExp(url.split("?rootuserid")[0], 'i');