更新细节
This commit is contained in:
parent
9cca6e0b99
commit
731f595db4
|
@ -17,7 +17,7 @@ export function apiProductLists(params: any) {
|
|||
|
||||
// 监测设备列表
|
||||
export function apiDeviceLists(params: any) {
|
||||
return request.get({ url: '/device.device/lists', params })
|
||||
return request.get({ url: '/device.device/datas', params })
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -101,10 +101,10 @@ const { optionsData } = useDictOptions<{
|
|||
|
||||
const loading = ref(false)
|
||||
|
||||
const queryProduct = async (land_id: string) => {
|
||||
const queryProduct = async (query: string) => {
|
||||
loading.value = true
|
||||
const productList = await apiProductLists({
|
||||
land_id: land_id ?? ''
|
||||
name: query ?? ''
|
||||
})
|
||||
optionsData.product = productList
|
||||
loading.value = false
|
||||
|
|
|
@ -32,10 +32,10 @@
|
|||
:loading="loading"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in deviceOptions"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value"
|
||||
v-for="(item, index) in optionsData.device"
|
||||
:key="index"
|
||||
:label="item.deviceinfo"
|
||||
:value="item.id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
@ -45,6 +45,7 @@
|
|||
</template>
|
||||
|
||||
<script lang="ts" setup name="landEdit">
|
||||
import { useDictOptions } from '@/hooks/useDictOptions'
|
||||
import type { FormInstance } from 'element-plus'
|
||||
import Popup from '@/components/popup/index.vue'
|
||||
import { apiProductBind, apiDeviceLists } from '@/api/product'
|
||||
|
@ -93,31 +94,23 @@ const setFormData = async (data: Record<any, any>) => {
|
|||
}
|
||||
}
|
||||
|
||||
interface ListItem {
|
||||
value: string
|
||||
label: string
|
||||
}
|
||||
const deviceOptions = ref<ListItem[]>([])
|
||||
const { optionsData } = useDictOptions<{
|
||||
device: any[]
|
||||
}>({
|
||||
device: {
|
||||
api: apiDeviceLists
|
||||
}
|
||||
})
|
||||
|
||||
const loading = ref(false)
|
||||
|
||||
const queryDevice = async (query: string) => {
|
||||
if (query) {
|
||||
loading.value = true
|
||||
const deviceList = await apiDeviceLists({
|
||||
name: query
|
||||
name: query ?? ''
|
||||
})
|
||||
optionsData.device = deviceList
|
||||
loading.value = false
|
||||
if (deviceList.count > 0) {
|
||||
deviceOptions.value = deviceList.lists.map((device: any) => {
|
||||
return { value: `${device.id}`, label: `ID: ${device.id} / 名称: ${device.name}` }
|
||||
})
|
||||
} else {
|
||||
deviceOptions.value = []
|
||||
}
|
||||
loading.value = false
|
||||
} else {
|
||||
deviceOptions.value = []
|
||||
}
|
||||
}
|
||||
|
||||
// 提交按钮
|
||||
|
|
|
@ -84,7 +84,7 @@
|
|||
<span>{{ row.create_time ? timeFormat(row.create_time, 'yyyy-mm-dd hh:MM:ss') : '' }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="260" align="center" fixed="right">
|
||||
<el-table-column label="操作" width="300" align="center" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button
|
||||
v-perms="['land.product/edit']"
|
||||
|
@ -94,14 +94,14 @@
|
|||
>
|
||||
编辑
|
||||
</el-button>
|
||||
<!-- <el-button
|
||||
<el-button
|
||||
v-perms="['land.product/bind']"
|
||||
type="primary"
|
||||
link
|
||||
@click="handleBind(row)"
|
||||
>
|
||||
绑定设备
|
||||
</el-button> -->
|
||||
</el-button>
|
||||
<el-button v-perms="['device.device/lists']" type="primary" link >
|
||||
<router-link
|
||||
:to="{
|
||||
|
|
|
@ -42,6 +42,11 @@ class DeviceController extends BaseAdminController
|
|||
return $this->dataLists(new DeviceLists());
|
||||
}
|
||||
|
||||
public function datas()
|
||||
{
|
||||
$datas = (new DeviceLogic())->datas(input(''));
|
||||
return $this->success('', $datas);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 添加
|
||||
|
|
|
@ -127,6 +127,38 @@ class DeviceLogic extends BaseLogic
|
|||
}
|
||||
}
|
||||
|
||||
public function datas($params): array
|
||||
{
|
||||
$userWhere['d.user_id'] = -1;
|
||||
if (!empty($params['user_id'])) {
|
||||
$userWhere['d.user_id'] = $params['user_id'];
|
||||
}
|
||||
if (!request()->adminInfo['root'] && request()->adminInfo['user_id']) {
|
||||
$userWhere['d.user_id'] = request()->adminInfo['user_id'];
|
||||
}
|
||||
if (request()->adminInfo['root']) {
|
||||
unset($userWhere['d.user_id']);
|
||||
}
|
||||
$queryWhere = [];
|
||||
if (!empty($params['name'])) {
|
||||
$queryWhere[] = ['d.name', 'like', '%' . $params['name'] . '%'];
|
||||
}
|
||||
$deviceIdArray = Db::name('product_device')->column('device_id');
|
||||
$lists = Db::name('device')->alias('d')
|
||||
->where($userWhere)->where($queryWhere)->whereNotIn('d.id', $deviceIdArray)
|
||||
->leftJoin('product_device pd','pd.device_id = d.id')
|
||||
->leftJoin('product p','p.id = pd.product_id')
|
||||
->leftJoin('user u','u.id = p.user_id')
|
||||
->field('d.*')
|
||||
->limit(0, 100)
|
||||
->order(['d.id' => 'desc'])
|
||||
->select()->toArray();
|
||||
foreach ($lists as &$item) {
|
||||
$item['deviceinfo'] = 'ID:' . $item['id'] . ' / 名称:' . $item['name'];
|
||||
}
|
||||
return $lists;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除
|
||||
|
|
|
@ -141,12 +141,12 @@ class ProductLogic extends BaseLogic
|
|||
unset($userWhere['p.user_id']);
|
||||
}
|
||||
$queryWhere = [];
|
||||
if (!empty($params['land_id'])) {
|
||||
$queryWhere['l.id'] = $params['land_id'];
|
||||
if (!empty($params['name'])) {
|
||||
$queryWhere[] = ['p.name', 'like', '%' . $params['name'] . '%'];
|
||||
}
|
||||
$productIdArray = Db::name('land_product')->column('product_id');
|
||||
$lists = Db::name('product')->alias('p')
|
||||
->where($userWhere)->whereNotIn('p.id', $productIdArray)
|
||||
->where($userWhere)->where($queryWhere)->whereNotIn('p.id', $productIdArray)
|
||||
->leftJoin('user u','u.id = p.user_id')
|
||||
->field('p.*')
|
||||
->limit(0, 100)
|
||||
|
@ -188,9 +188,10 @@ class ProductLogic extends BaseLogic
|
|||
|
||||
public static function bind($params): bool
|
||||
{
|
||||
$root = (request()->adminInfo)['root'];
|
||||
$userId = (request()->adminInfo)['user_id'];
|
||||
if (!empty($params['id'])) {
|
||||
$userId = Db::name('product')->where('id', $params['id'])->value('user_id');
|
||||
if ($root && !empty($params['user_id'])) {
|
||||
$userId = $params['user_id'];
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue