|
@@ -3,14 +3,14 @@
|
|
|
<n-card title="认证鉴权" :bordered="false" class="rounded-16px shadow-sm">
|
|
|
<n-space class="pb-12px" justify="space-between">
|
|
|
<n-space>
|
|
|
- <!--<n-button type="primary" @click="handleAddTable">
|
|
|
+ <n-button type="primary" @click="handleAddTable">
|
|
|
<icon-ic-round-plus class="mr-4px text-20px" />
|
|
|
新增
|
|
|
- </n-button>-->
|
|
|
+ </n-button>
|
|
|
</n-space>
|
|
|
<n-space align="center" :size="18">
|
|
|
<n-input-group>
|
|
|
- <n-input v-model:value="topicName" />
|
|
|
+ <n-input v-model:value="topic" />
|
|
|
<n-button type="primary" @click="handleSearch">搜索</n-button>
|
|
|
</n-input-group>
|
|
|
<n-button size="small" type="primary" @click="getTableData">
|
|
@@ -20,7 +20,13 @@
|
|
|
</n-space>
|
|
|
</n-space>
|
|
|
<n-data-table :columns="columns" :data="tableData" :loading="loading" :pagination="pagination" />
|
|
|
- <table-action-modal v-model:visible="visible" :type="modalType" :edit-data="editData" />
|
|
|
+ <table-action-modal
|
|
|
+ v-model:visible="visible"
|
|
|
+ :type="modalType"
|
|
|
+ :edit-data="editData"
|
|
|
+ :pasture-enum-list-data="pastureEnumListData"
|
|
|
+ :topic-enum-list-data="topicEnumListData"
|
|
|
+ />
|
|
|
</n-card>
|
|
|
</div>
|
|
|
</template>
|
|
@@ -28,35 +34,73 @@
|
|
|
<script setup lang="tsx">
|
|
|
import { reactive, ref } from 'vue';
|
|
|
import type { Ref } from 'vue';
|
|
|
-import { NButton, NSpace, NTag } from 'naive-ui';
|
|
|
-import type { DataTableColumns, PaginationProps } from 'naive-ui';
|
|
|
+import { NButton, NSpace, NTag, NPopconfirm } from 'naive-ui';
|
|
|
+import type { DataTableColumns, PaginationProps, SelectOption } from 'naive-ui';
|
|
|
import { MqttAuthIsShowLabels } from '@/constants';
|
|
|
import { useBoolean, useLoading } from '@/hooks';
|
|
|
-import { fetchMqttAuthList } from '@/service/api/mqtt';
|
|
|
+import { fetchMqttAuthList, mqttAuthDelete, pastureEnumList, topicEnumList } from '@/service/api/mqtt';
|
|
|
import TableActionModal from '../authentication/components/table-action-modal.vue';
|
|
|
import type { ModalType } from '../authentication/components/table-action-modal.vue';
|
|
|
|
|
|
const { loading, startLoading, endLoading } = useLoading(false);
|
|
|
-const { bool: visible } = useBoolean();
|
|
|
-const topicName = ref('');
|
|
|
+const { bool: visible, setTrue: openModal } = useBoolean();
|
|
|
+const topic = ref('');
|
|
|
const tableData = ref<ApiMqttAuth.Auth[]>([]);
|
|
|
+const editData = ref<Mqtt.Auth | null>(null);
|
|
|
+const modalType = ref<ModalType>('add');
|
|
|
+const pastureEnumListData = ref<SelectOption[]>([]);
|
|
|
+const topicEnumListData = ref<SelectOption[]>([]);
|
|
|
+
|
|
|
+function setPastureList(data: SelectOption[]) {
|
|
|
+ pastureEnumListData.value = data;
|
|
|
+}
|
|
|
+
|
|
|
+function setTopicList(data: SelectOption[]) {
|
|
|
+ topicEnumListData.value = data;
|
|
|
+}
|
|
|
+
|
|
|
+function setEditData(data: Mqtt.Auth | null) {
|
|
|
+ editData.value = data;
|
|
|
+}
|
|
|
+
|
|
|
function setTableData(data: ApiMqttAuth.Auth[]) {
|
|
|
tableData.value = data;
|
|
|
}
|
|
|
|
|
|
+function setModalType(type: ModalType) {
|
|
|
+ modalType.value = type;
|
|
|
+}
|
|
|
+
|
|
|
async function getTableData() {
|
|
|
startLoading();
|
|
|
- const { data } = await fetchMqttAuthList(1, 10, topicName.value);
|
|
|
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
|
+ const { data } = await fetchMqttAuthList(pagination.page, pagination.pageSize, topic.value);
|
|
|
if (data) {
|
|
|
- setTimeout(() => {
|
|
|
- setTableData(data);
|
|
|
- endLoading();
|
|
|
- }, 1000);
|
|
|
+ setTableData(data);
|
|
|
+ endLoading();
|
|
|
} else {
|
|
|
endLoading();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+async function getPastureEnumList() {
|
|
|
+ const { data } = await pastureEnumList();
|
|
|
+ if (data) {
|
|
|
+ setTimeout(() => {
|
|
|
+ setPastureList(data);
|
|
|
+ }, 1000);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+async function getTopicEnumList() {
|
|
|
+ const { data } = await topicEnumList();
|
|
|
+ if (data) {
|
|
|
+ setTimeout(() => {
|
|
|
+ setTopicList(data);
|
|
|
+ }, 1000);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
const columns: Ref<DataTableColumns<ApiMqttAuth.Auth>> = ref([
|
|
|
{
|
|
|
type: 'selection',
|
|
@@ -67,6 +111,11 @@ const columns: Ref<DataTableColumns<ApiMqttAuth.Auth>> = ref([
|
|
|
title: '序号',
|
|
|
align: 'center'
|
|
|
},
|
|
|
+ {
|
|
|
+ key: 'pasture_name',
|
|
|
+ title: '牧场名称',
|
|
|
+ align: 'center'
|
|
|
+ },
|
|
|
{
|
|
|
key: 'mount_point',
|
|
|
title: '挂载点',
|
|
@@ -83,12 +132,17 @@ const columns: Ref<DataTableColumns<ApiMqttAuth.Auth>> = ref([
|
|
|
align: 'center'
|
|
|
},
|
|
|
{
|
|
|
- key: 'publish_acl',
|
|
|
- title: '发布topic',
|
|
|
+ key: 'topic_name_stings',
|
|
|
+ title: 'topic名称',
|
|
|
align: 'center'
|
|
|
},
|
|
|
{
|
|
|
key: 'subscribe_acl',
|
|
|
+ title: '发布topic',
|
|
|
+ align: 'center'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: 'publish_acl',
|
|
|
title: '订阅topic',
|
|
|
align: 'center'
|
|
|
},
|
|
@@ -107,7 +161,7 @@ const columns: Ref<DataTableColumns<ApiMqttAuth.Auth>> = ref([
|
|
|
}
|
|
|
return <span></span>;
|
|
|
}
|
|
|
- } /*,
|
|
|
+ },
|
|
|
{
|
|
|
key: 'actions',
|
|
|
title: '操作',
|
|
@@ -131,24 +185,36 @@ const columns: Ref<DataTableColumns<ApiMqttAuth.Auth>> = ref([
|
|
|
</NSpace>
|
|
|
);
|
|
|
}
|
|
|
- } */
|
|
|
+ }
|
|
|
]) as Ref<DataTableColumns<ApiMqttAuth.Auth>>;
|
|
|
|
|
|
-const editData = ref<ApiMqttAuth.Auth | null>(null);
|
|
|
-const modalType = ref<ModalType>('add');
|
|
|
-/*
|
|
|
-function setModalType(type: ModalType) {
|
|
|
- modalType.value = type;
|
|
|
-}
|
|
|
-
|
|
|
-function setEditData(data: ApiMqttAuth.Auth | null) {
|
|
|
- editData.value = data;
|
|
|
-}
|
|
|
-
|
|
|
+const pagination: PaginationProps = reactive({
|
|
|
+ page: 1,
|
|
|
+ pageSize: 10,
|
|
|
+ showSizePicker: true,
|
|
|
+ pageSizes: [10, 15, 20, 25, 30],
|
|
|
+ onChange: (page: number) => {
|
|
|
+ pagination.page = page;
|
|
|
+ },
|
|
|
+ onUpdatePageSize: (pageSize: number) => {
|
|
|
+ pagination.pageSize = pageSize;
|
|
|
+ pagination.page = 1;
|
|
|
+ }
|
|
|
+});
|
|
|
|
|
|
-function handleAddTable() {
|
|
|
- openModal();
|
|
|
- setModalType('add');
|
|
|
+async function handleSearch() {
|
|
|
+ if (!topic.value) {
|
|
|
+ window.$message?.warning('请输入主题名称');
|
|
|
+ } else {
|
|
|
+ startLoading();
|
|
|
+ const { data } = await fetchMqttAuthList(pagination.page, pagination.pageSize, topic.value);
|
|
|
+ if (data) {
|
|
|
+ setTableData(data);
|
|
|
+ endLoading();
|
|
|
+ } else {
|
|
|
+ endLoading();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
function handleEditTable(rowId: number) {
|
|
@@ -169,32 +235,16 @@ function handleDeleteTable(rowId: number) {
|
|
|
});
|
|
|
init();
|
|
|
}
|
|
|
-*/
|
|
|
-
|
|
|
-const pagination: PaginationProps = reactive({
|
|
|
- page: 1,
|
|
|
- pageSize: 10,
|
|
|
- showSizePicker: true,
|
|
|
- pageSizes: [10, 15, 20, 25, 30],
|
|
|
- onChange: (page: number) => {
|
|
|
- pagination.page = page;
|
|
|
- },
|
|
|
- onUpdatePageSize: (pageSize: number) => {
|
|
|
- pagination.pageSize = pageSize;
|
|
|
- pagination.page = 1;
|
|
|
- }
|
|
|
-});
|
|
|
|
|
|
-function handleSearch() {
|
|
|
- if (!topicName.value) {
|
|
|
- window.$message?.warning('请输入主题名称');
|
|
|
- } else {
|
|
|
- startLoading();
|
|
|
- }
|
|
|
+function handleAddTable() {
|
|
|
+ openModal();
|
|
|
+ setModalType('add');
|
|
|
}
|
|
|
|
|
|
function init() {
|
|
|
getTableData();
|
|
|
+ getPastureEnumList();
|
|
|
+ getTopicEnumList();
|
|
|
}
|
|
|
|
|
|
// 初始化
|