media_player_client/src/components/SystenSettingAdvancedNetwor...

376 lines
11 KiB
Vue
Raw Normal View History

<template>
<q-dialog
persistent
v-model="show_dialog"
@before-hide="resetData"
@keydown="
(evt) => {
if (evt.keyCode == 27) {
show_dialog = false;
}
}
"
>
<q-card class="overflow-hidden" style="max-width: 60vw">
<q-form @submit="onSubmit">
<q-card-section class="q-ma-none q-pa-sm">
<div class="row">
<div class="col-auto text-h6">
{{ $t("advanced network setting") }}
</div>
<q-space />
<div>
<q-btn flat round icon="close" color="red" v-close-popup>
<q-tooltip>
{{ $t("close") }}
</q-tooltip>
</q-btn>
</div>
</div>
</q-card-section>
<q-card-section
class="scroll q-pa-xs q-ma-none"
style="width: 60vw; height: 65vh"
>
2022-06-29 15:22:15 +08:00
<q-card-section class="q-pb-none">
<q-card>
<q-card-section>
<q-item class="q-pa-none">
<q-item-section avatar class="header_label_2 text-left">{{
$t("host name") + ":"
}}</q-item-section>
<q-item-section>
<q-input
v-model="host_name"
maxlength="20"
:rules="[
(val) =>
(val && val.length > 0) ||
$t('Please type something'),
(val) =>
isEnglishOrNum(val) ||
$t(
'Host names can only be numbers and letters and _-'
),
]"
lazy-rules
/>
</q-item-section>
</q-item>
</q-card-section>
</q-card>
</q-card-section>
<q-card-section>
<q-table
ref="advance_ip_table"
class="advance-ip-table"
:title="$t('ip address')"
:rows="advance_ip_rows"
:columns="advance_ip_columns"
row-key="uuid"
:hide-bottom="true"
selection="single"
virtual-scroll
:virtual-scroll-item-size="48"
:virtual-scroll-sticky-size-start="48"
:rows-per-page-options="[0]"
@row-click="
(evt, row, index) => {
if (advance_ip_table_selected.length) {
advance_ip_table_selected =
advance_ip_table_selected[0].uuid == row.uuid
? []
: [row];
} else {
advance_ip_table_selected = [row];
}
2022-06-29 15:22:15 +08:00
}
"
v-model:selected="advance_ip_table_selected"
>
<template v-slot:top="props">
<div class="col-2 q-table__title">{{ $t("ip address") }}</div>
2022-06-29 15:22:15 +08:00
<q-space />
2022-06-29 15:22:15 +08:00
<q-btn
flat
color="primary"
:label="$t('add row')"
class="col-2"
@click="advance_ip_addRow"
/>
<q-btn
:disable="advance_ip_table_selected.length == 0"
flat
color="primary"
:label="$t('edit row')"
class="col-2"
@click="advance_ip_editRow"
/>
<q-btn
:disable="advance_ip_table_selected.length == 0"
flat
color="primary"
:label="$t('delete row')"
class="col-2"
@click="
advance_ip_table_selected.length &&
(advance_ip_rows = advance_ip_rows.filter(
(element) =>
element && element != advance_ip_table_selected[0]
)) &&
(advance_ip_table_selected = [])
"
/>
</template>
</q-table>
</q-card-section>
</q-card-section>
<q-separator />
<q-card-actions align="right">
<q-btn flat :label="$t('Cancel')" color="primary" v-close-popup />
<q-btn
ref="accept"
flat
:label="$t('Accept')"
type="submit"
color="primary"
/>
</q-card-actions>
</q-form>
</q-card>
</q-dialog>
2022-06-28 20:06:23 +08:00
<advanced-ip-address-dialog
ref="advanced_ip_address_dialog"
:showDns="false"
/>
</template>
<style scoped>
.header_label {
width: 15%;
}
.header_label_2 {
2022-06-29 15:22:15 +08:00
width: 20%;
align-items: center;
}
</style>
2022-06-29 15:22:15 +08:00
<style lang="sass">
.advance-ip-table
/* height or max-height is important */
max-height: 46vh
.q-table__top,
.q-table__bottom,
thead tr:first-child th /* bg color is important for th; just specify one */
background-color: #fff
thead tr th
position: sticky
z-index: 1
/* this will be the loading indicator */
thead tr:last-child th
/* height of all previous header rows */
top: 48px
thead tr:first-child th
top: 0
</style>
<script lang="ts">
import { defineComponent, ref, Ref, reactive } from "vue";
import { useStore } from "src/store";
import { useQuasar, copyToClipboard, uid } from "quasar";
import { useI18n } from "vue-i18n";
import GlobalData from "src/common/GlobalData";
import AdvancedIpAddressDialog from "src/components/AdvancedIpAddressDialog.vue";
2022-06-28 20:06:23 +08:00
import { AdvancedIpAddressEntity } from "src/entities/AdvancedIpAddressEntity";
export default defineComponent({
name: "ComponentSystenSettingAdvancedNetworkDialog",
components: { AdvancedIpAddressDialog },
setup() {
let $store = useStore();
let $q = useQuasar();
let $t = useI18n();
const advanced_ip_address_dialog: Ref<any> = ref(null);
let show_dialog = ref(false);
2022-06-28 20:06:23 +08:00
const advance_ip_table_selected: Ref<AdvancedIpAddressEntity[]> = ref([]);
2022-06-29 15:22:15 +08:00
const host_name = ref("player");
const advance_ip_columns = [
{
name: "ip_address",
required: true,
label: $t.t("ip address"),
align: "left",
field: "ip_address",
},
{
name: "netmask",
align: "left",
label: $t.t("netmask"),
field: "netmask",
},
{
name: "gateway",
align: "left",
label: $t.t("gateway"),
field: "gateway",
},
2022-06-28 20:06:23 +08:00
// {
// name: "dns1",
// align: "left",
// field: "dns1",
// label: $t.t("dns server") + " 1",
// },
// {
// name: "dns2",
// align: "left",
// field: "dns2",
// label: $t.t("dns server") + " 2",
// },
];
2022-06-28 20:06:23 +08:00
const advance_ip_rows: Ref<AdvancedIpAddressEntity[]> = ref([]);
const isIpAddress = (str: string) => {
return (
str == "localhost" ||
/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/.test(
str
)
);
};
let _resolove: any = null;
return {
show_dialog,
advanced_ip_address_dialog,
advance_ip_columns,
advance_ip_rows,
advance_ip_table_selected,
2022-06-29 15:22:15 +08:00
host_name,
loga(a: any) {
console.log(a);
},
2022-06-28 20:06:23 +08:00
async showDialogAsync(_data: AdvancedIpAddressEntity[]) {
if (_resolove) {
_resolove();
_resolove = null;
}
return new Promise((resolove) => {
2022-06-28 20:06:23 +08:00
_resolove = resolove;
2022-06-29 15:22:15 +08:00
GlobalData.getInstance()
.getCurrentClient()
?.getSystemNetworkInfo()
.then((response) => {
if (response) {
host_name.value = (response.host_name ?? "player").trim();
}
});
2022-06-28 20:06:23 +08:00
if (Array.isArray(_data)) {
for (const item of _data) {
if (item) {
(<any>item).uuid = uid();
advance_ip_rows.value.push(item);
}
}
}
show_dialog.value = true;
});
},
resetData() {
if (_resolove) {
_resolove();
_resolove = null;
}
advance_ip_rows.value = [];
advance_ip_table_selected.value = [];
2022-06-29 15:22:15 +08:00
host_name.value = "player";
},
async onSubmit() {
2022-06-28 20:06:23 +08:00
// let success = false;
try {
if (_resolove) {
try {
2022-06-29 15:22:15 +08:00
_resolove({
ip_address_list: advance_ip_rows.value,
host_name: host_name.value,
});
} catch {
_resolove(null);
}
}
} catch {}
show_dialog.value = false;
// $q.notify({
// color: success ? "positive" : "negative",
// icon: success ? "done" : "warning",
// message:
// $t.t("set serialport") +
// (success ? $t.t("success") : $t.t("fail")) +
// "!",
// position: "top",
// timeout: 1500,
// });
},
async advance_ip_addRow() {
const data: any =
await advanced_ip_address_dialog.value.showDialogAsync(
"edit",
null,
advance_ip_rows.value.map((element: any) => element.ip_address)
);
if (data) {
2022-06-28 20:06:23 +08:00
const push_data = new AdvancedIpAddressEntity();
(<any>push_data).uuid = uid();
push_data.ip_address = data.ip_address;
push_data.gateway = data.gateway;
push_data.netmask = data.netmask;
// push_data.dns1= data.dns1
// push_data.dns2= data.dns2
advance_ip_rows.value.push(push_data);
}
},
async advance_ip_editRow() {
if (advance_ip_table_selected.value.length) {
const data: any =
await advanced_ip_address_dialog.value.showDialogAsync(
"edit",
advance_ip_table_selected.value[0],
advance_ip_rows.value.map((element: any) => element.ip_address)
);
if (data) {
advance_ip_table_selected.value[0].ip_address = data.ip_address;
advance_ip_table_selected.value[0].gateway = data.gateway;
advance_ip_table_selected.value[0].netmask = data.netmask;
2022-06-28 20:06:23 +08:00
// advance_ip_table_selected.value[0].dns1 = data.dns1;
// advance_ip_table_selected.value[0].dns2 = data.dns2;
}
}
},
2022-06-29 15:22:15 +08:00
isEnglishOrNum(str: string) {
return /^[0-9a-zA-Z_\-]+$/.test(str);
},
};
},
});
</script>