模式添加索引

This commit is contained in:
fangxiang 2021-09-07 18:03:50 +08:00
parent 1156d2f4c7
commit e6b3d7ce94
5 changed files with 86 additions and 13 deletions

View File

@ -443,20 +443,21 @@ export default class ClientConnection {
}
}
public async addMode(group_uuid?: string, name?: string) {
public async addMode(group_uuid?: string, name?: string, index?: number) {
try {
console.log(index);
return await this.doRpc<Protocol.AddModeResponseEntity>(
new Protocol.AddModeRequestEntity(0, name, group_uuid)
new Protocol.AddModeRequestEntity(0, name, group_uuid, index)
);
} catch (e) {
console.error(e);
}
}
public async editMode(uuid?: string, name?: string) {
public async editMode(uuid?: string, name?: string, index?: number) {
try {
return await this.doRpc<Protocol.EditModeResponseEntity>(
new Protocol.EditModeRequestEntity(0, name, uuid)
new Protocol.EditModeRequestEntity(0, name, uuid, index)
);
} catch (e) {
console.error(e);

View File

@ -110,6 +110,32 @@
</q-input>
</q-item-section>
</q-item>
<q-item>
<q-item-section>
<q-input
autofocus
:loading="loading"
:disable="loading"
filled
type="number"
min="0"
max="65535"
v-model.number="index"
:label="$t('mode index')"
:hint="$t('please input mode index')"
lazy-rules
:rules="[checkIndex]"
@keydown="
(evt) => {
if (evt.keyCode == 13) {
$refs?.accept?.click();
}
}
"
>
</q-input>
</q-item-section>
</q-item>
</q-list>
</q-card-section>
@ -151,6 +177,8 @@ import { useStore } from "src/store";
import GlobalData from "src/common/GlobalData";
import { useQuasar } from "quasar";
import { useI18n } from "vue-i18n";
import { api } from "boot/axios";
import { HttpProtocol } from "src/entities/HttpProtocol";
export default defineComponent({
name: "ComponentModeDialog",
@ -163,6 +191,7 @@ export default defineComponent({
let show_dialog = ref(false);
let type = ref(1);
let name = ref(null);
let index = ref(0);
let uuid = ref("");
const selected: any = ref(null);
let loading = ref(false);
@ -184,7 +213,7 @@ export default defineComponent({
const requestAddMode = async () => {
let response = await GlobalData.getInstance()
.getCurrentClient()
?.addMode(selected.value, name.value ?? "");
?.addMode(selected.value, name.value ?? "", index.value);
if (response) {
$q.notify({
color: response.success ? "positive" : "negative",
@ -202,7 +231,7 @@ export default defineComponent({
const requestEditMode = async () => {
let response = await GlobalData.getInstance()
.getCurrentClient()
?.editMode(uuid.value, name.value ?? "");
?.editMode(uuid.value, name.value ?? "", index.value);
if (response) {
$q.notify({
color: response.success ? "positive" : "negative",
@ -221,6 +250,7 @@ export default defineComponent({
show_dialog,
type,
name,
index,
uuid,
selected,
loading,
@ -233,6 +263,7 @@ export default defineComponent({
name.value = options.data?.name ?? null;
selected.value = options.data?.item_data?.group_uuid ?? null;
uuid.value = options.data?.item_data?.uuid ?? null;
index.value = options.data?.item_data?.number ?? 0;
} else {
selected.value = options.data?.uuid ?? null;
uuid.value = options.data?.uuid ?? null;
@ -248,7 +279,37 @@ export default defineComponent({
treeNodesFilter(node: any, filter: any) {
return node.is_group;
},
checkIndex(val: number) {
return new Promise(async (resolve, reject) => {
if (val < 0) {
resolve($t.t("Please type 0~65535"));
} else {
try {
let url = GlobalData.getInstance().createCurrentRequestUrl();
if (!url) {
url = new URL(window.location.hostname);
}
url.pathname = HttpProtocol.RequestCheckModeIndex;
url.searchParams.append("index", index.value.toString());
let response = (await api.get(url.toString())).data as boolean;
if (typeof response != "boolean") {
try {
response = JSON.parse(response);
} catch {
response = false;
}
}
if (!response) {
resolve($t.t("index exised!"));
} else {
resolve(true);
}
} catch (e) {
resolve($t.t("check error"));
}
}
});
},
async onSubmit() {
loading.value = true;
try {

View File

@ -7,6 +7,7 @@ export namespace HttpProtocol {
export const RequestPathCreateDirectory = "/create_directory";
export const RequestPathDeleteFile = "/delete_file";
export const RequestPathRenameFile = "/rename_file";
export const RequestCheckModeIndex = "/check_mode_index";
export const HttpUploadTypeNormal = "U_T_Normal";
export const UploadTypeBackgroundImage = "U_T_BACKGROUND_IMAGE";

View File

@ -692,12 +692,19 @@ export namespace Protocol {
export class AddModeRequestEntity extends Protocol.PacketEntity {
name: string;
group_uuid: string;
constructor(rcp_id?: number, name?: string, group_uuid?: string) {
number: number;
constructor(
rcp_id?: number,
name?: string,
group_uuid?: string,
number?: number
) {
super();
this.rpc_id = rcp_id ?? 0;
this.command = Protocol.Commands.kRpcAddMode;
this.name = name ?? "";
this.group_uuid = group_uuid ?? "";
this.number = number ?? 0;
}
}
@ -713,12 +720,19 @@ export namespace Protocol {
export class EditModeRequestEntity extends Protocol.PacketEntity {
name: string;
uuid: string;
constructor(rcp_id?: number, name?: string, uuid?: string) {
number: number;
constructor(
rcp_id?: number,
name?: string,
uuid?: string,
number?: number
) {
super();
this.rpc_id = rcp_id ?? 0;
this.command = Protocol.Commands.kRpcEditMode;
this.name = name ?? "";
this.uuid = uuid ?? "";
this.number = number ?? 0;
}
}

View File

@ -137,10 +137,6 @@ export default defineComponent({
const calcWallVWScaler = (wall_width: number, wall_height: number) => {
if (wall.value && wall.value.parentElement) {
console.log($store.state.device_screen_width);
console.log($store.state.device_screen_height);
console.log(wall_width);
console.log(wall_height);
wall_height_scaler.value =
$store.state.device_screen_height / wall_height;
wall_width_scaler.value = $store.state.device_screen_width / wall_width;