私域操盘手 - 表单方式提交设备添加暂不支持

This commit is contained in:
柳清爽
2025-05-09 10:24:12 +08:00
parent b6d7450afd
commit 45e133e8a4
3 changed files with 37 additions and 105 deletions

View File

@@ -93,6 +93,7 @@ export default function DeviceDetailPage() {
momentsSync: false, momentsSync: false,
aiChat: false aiChat: false
}) })
const [tabChangeLoading, setTabChangeLoading] = useState(false)
useEffect(() => { useEffect(() => {
if (!params.id) return if (!params.id) return
@@ -330,6 +331,9 @@ export default function DeviceDetailPage() {
const handleTabChange = (value: string) => { const handleTabChange = (value: string) => {
setActiveTab(value) setActiveTab(value)
// 显示过渡加载状态
setTabChangeLoading(true)
// 当切换到"关联账号"标签时,获取最新的关联微信账号信息 // 当切换到"关联账号"标签时,获取最新的关联微信账号信息
if (value === "accounts") { if (value === "accounts") {
fetchRelatedAccounts() fetchRelatedAccounts()
@@ -339,6 +343,11 @@ export default function DeviceDetailPage() {
if (value === "history") { if (value === "history") {
fetchHandleLogs() fetchHandleLogs()
} }
// 设置短暂的延迟来关闭加载状态,模拟加载过程
setTimeout(() => {
setTabChangeLoading(false)
}, 300)
} }
// 处理功能开关状态变化 // 处理功能开关状态变化
@@ -599,6 +608,15 @@ export default function DeviceDetailPage() {
<TabsContent value="info"> <TabsContent value="info">
<Card className="p-4 space-y-4"> <Card className="p-4 space-y-4">
{/* 标签切换时的加载状态 */}
{tabChangeLoading && (
<div className="absolute inset-0 bg-white bg-opacity-80 flex justify-center items-center z-10">
<div className="flex flex-col items-center space-y-3">
<div className="w-8 h-8 rounded-full border-2 border-blue-500 border-t-transparent animate-spin"></div>
<div className="text-gray-500 text-sm">...</div>
</div>
</div>
)}
<div className="space-y-4"> <div className="space-y-4">
<div className="flex items-center justify-between"> <div className="flex items-center justify-between">
<div className="space-y-0.5"> <div className="space-y-0.5">
@@ -697,6 +715,15 @@ export default function DeviceDetailPage() {
</div> </div>
<ScrollArea className="h-[calc(100vh-300px)]"> <ScrollArea className="h-[calc(100vh-300px)]">
{/* 标签切换时的加载状态 */}
{tabChangeLoading && (
<div className="absolute inset-0 bg-white bg-opacity-80 flex justify-center items-center z-10">
<div className="flex flex-col items-center space-y-3">
<div className="w-8 h-8 rounded-full border-2 border-blue-500 border-t-transparent animate-spin"></div>
<div className="text-gray-500 text-sm">...</div>
</div>
</div>
)}
{accountsLoading && ( {accountsLoading && (
<div className="flex justify-center items-center py-8"> <div className="flex justify-center items-center py-8">
<div className="w-6 h-6 rounded-full border-2 border-blue-500 border-t-transparent animate-spin mr-2"></div> <div className="w-6 h-6 rounded-full border-2 border-blue-500 border-t-transparent animate-spin mr-2"></div>
@@ -781,6 +808,15 @@ export default function DeviceDetailPage() {
</div> </div>
<ScrollArea className="h-[calc(min(80vh, 500px))]"> <ScrollArea className="h-[calc(min(80vh, 500px))]">
{/* 标签切换时的加载状态 */}
{tabChangeLoading && (
<div className="absolute inset-0 bg-white bg-opacity-80 flex justify-center items-center z-10">
<div className="flex flex-col items-center space-y-3">
<div className="w-8 h-8 rounded-full border-2 border-blue-500 border-t-transparent animate-spin"></div>
<div className="text-gray-500 text-sm">...</div>
</div>
</div>
)}
{logsLoading && handleLogs.length === 0 ? ( {logsLoading && handleLogs.length === 0 ? (
<div className="flex justify-center items-center py-8"> <div className="flex justify-center items-center py-8">
<div className="w-6 h-6 rounded-full border-2 border-blue-500 border-t-transparent animate-spin mr-2"></div> <div className="w-6 h-6 rounded-full border-2 border-blue-500 border-t-transparent animate-spin mr-2"></div>

View File

View File

@@ -2,123 +2,19 @@
namespace app\cunkebao\controller\device; namespace app\cunkebao\controller\device;
use app\common\model\Device as DeviceModel;
use app\common\model\DeviceHandleLog as DeviceHandleLogModel;
use app\cunkebao\controller\BaseController; use app\cunkebao\controller\BaseController;
use library\ResponseHelper;
use library\s2\CurlHandle;
use think\Db;
use think\Validate;
/** /**
* 设备管理控制器 * 设备管理控制器
*/ */
class PostAddDeviceV1Controller extends BaseController class PostAddDeviceV1Controller extends BaseController
{ {
/**
* 验证IMEI是否已存在
*
* @return void
* @throws \Exception
*/
protected function checkDeviceIsExist(): void
{
if ($this->request->param('imei')) {
$where = [
'imei' => $this->request->param('imei'),
'companyId' => $this->getUserInfo('companyId'),
];
$exist = DeviceModel::where($where)->count() > 0;
if ($exist) {
throw new \Exception('设备IMEI已存在', 400);
}
} else {
throw new \Exception('设备IMEI不能为空', 400);
}
}
protected function addDeviceToS2()
{
$curl = CurlHandle::getInstant();
// $curl->setMethod()
}
/**
* 添加设备
*
* @return void
*/
protected function addDevice()
{
$id = DeviceModel::addDevice(
$this->request->post()
);
}
/**
* 添加设备操作记录
*
* @param int $deviceId
* @return void
* @throws \Exception
*/
protected function addDeviceHandleLog(int $deviceId): void
{
DeviceHandleLogModel::addLog(
[
'deviceId' => $deviceId,
'content' => '添加设备',
'userId' => $this->getUserInfo('id'),
'companyId' => $this->getUserInfo('companyId'),
]
);
}
/**
* 数据验证
*
* @return $this
* @throws \Exception
*/
protected function dataValidate(): self
{
$validate = Validate::make([
'imei' => 'require|length:32',
'memo' => 'require|/\S+/'
]);
if (!$validate->check($this->request->post())) {
throw new \Exception($validate->getError(), 400);
}
return $this;
}
/** /**
* 添加设备 * 添加设备
* @return \think\response\Json * @return \think\response\Json
*/ */
public function index() public function index()
{ {
try { exit('暂未支持');
$this->dataValidate()->checkDeviceIsExist();
Db::startTrans();
$deviceId = $this->addDevice();
$this->addDeviceHandleLog($deviceId);
Db::commit();
return ResponseHelper::success();
} catch (\Exception $e) {
Db::rollback();
return ResponseHelper::error($e->getMessage(), $e->getCode());
}
} }
} }