fix: update selectors

This commit is contained in:
Qiuxia Fan 2022-03-10 10:20:33 +08:00
parent 1490a08315
commit aa88bce938
3 changed files with 44 additions and 45 deletions

View File

@ -38,7 +38,7 @@ export const eventStore = defineStore({
loading: false, loading: false,
events: [], events: [],
total: 0, total: 0,
services: [{ value: "", label: "All" }], services: [{ value: "", label: "" }],
instances: [{ value: "", label: "All" }], instances: [{ value: "", label: "All" }],
endpoints: [{ value: "", label: "All" }], endpoints: [{ value: "", label: "All" }],
condition: { condition: {

View File

@ -72,15 +72,15 @@ limitations under the License. -->
> >
<span v-else-if="eventKey.class === 'source'" class="source"> <span v-else-if="eventKey.class === 'source'" class="source">
<span <span
>{{ t("currentService") }}: >{{ t("service") }}:
{{ currentEvent[eventKey.class].service }}</span {{ currentEvent[eventKey.class].service }}</span
> >
<div v-show="currentEvent[eventKey.class].endpoint"> <div v-show="currentEvent[eventKey.class].endpoint">
{{ t("currentEndpoint") }}: {{ t("endpoint") }}:
{{ currentEvent[eventKey.class].endpoint }} {{ currentEvent[eventKey.class].endpoint }}
</div> </div>
<div v-show="currentEvent[eventKey.class].serviceInstance"> <div v-show="currentEvent[eventKey.class].serviceInstance">
{{ t("currentInstance") }}: {{ t("instance") }}:
{{ currentEvent[eventKey.class].serviceInstance }} {{ currentEvent[eventKey.class].serviceInstance }}
</div> </div>
</span> </span>

View File

@ -29,7 +29,7 @@ limitations under the License. -->
<div class="mr-5"> <div class="mr-5">
<span class="grey">{{ t("service") }}: </span> <span class="grey">{{ t("service") }}: </span>
<Selector <Selector
v-model="state.service.value" v-model="state.service"
:options="eventStore.services" :options="eventStore.services"
placeholder="Select a service" placeholder="Select a service"
@change="selectService" @change="selectService"
@ -40,7 +40,7 @@ limitations under the License. -->
<div class="mr-5"> <div class="mr-5">
<span class="grey mr-5">{{ t("instance") }}: </span> <span class="grey mr-5">{{ t("instance") }}: </span>
<Selector <Selector
v-model="state.instance.value" v-model="state.instance"
:options="eventStore.instances" :options="eventStore.instances"
placeholder="Select a instance" placeholder="Select a instance"
@change="selectInstance" @change="selectInstance"
@ -51,7 +51,7 @@ limitations under the License. -->
<div class="mr-5"> <div class="mr-5">
<span class="grey mr-5">{{ t("endpoint") }}: </span> <span class="grey mr-5">{{ t("endpoint") }}: </span>
<Selector <Selector
v-model="state.endpoint.value" v-model="state.endpoint"
:options="eventStore.endpoints" :options="eventStore.endpoints"
placeholder="Select a endpoint" placeholder="Select a endpoint"
@change="selectEndpoint" @change="selectEndpoint"
@ -71,7 +71,7 @@ limitations under the License. -->
/> />
</div> </div>
</div> </div>
<div class="flex-h mt-5"> <div class="mt-5">
<el-pagination <el-pagination
v-model:currentPage="pageNum" v-model:currentPage="pageNum"
v-model:page-size="pageSize" v-model:page-size="pageSize"
@ -82,12 +82,12 @@ limitations under the License. -->
small small
:style="`--el-pagination-bg-color: #f0f2f5; --el-pagination-button-disabled-bg-color: #f0f2f5;`" :style="`--el-pagination-bg-color: #f0f2f5; --el-pagination-button-disabled-bg-color: #f0f2f5;`"
/> />
<div> <!-- <div>
<el-button class="search" type="primary" @click="queryEvents"> <el-button class="search" type="primary" @click="queryEvents">
<Icon iconName="search" class="mr-5" /> <Icon iconName="search" class="mr-5" />
<span class="vm">{{ t("search") }}</span> <span class="vm">{{ t("search") }}</span>
</el-button> </el-button>
</div> </div> -->
</div> </div>
</nav> </nav>
</template> </template>
@ -108,16 +108,16 @@ const state = reactive<{
currentLayer: string; currentLayer: string;
layers: string[]; layers: string[];
eventType: string; eventType: string;
service: { id: string; value: string; label: string }; service: string;
instance: { id: string; value: string; label: string }; instance: string;
endpoint: { id: string; value: string; label: string }; endpoint: string;
}>({ }>({
currentLayer: "", currentLayer: "",
layers: [], layers: [],
eventType: "", eventType: "",
service: { id: "", value: "", label: "" }, service: "",
instance: { id: "", value: "", label: "" }, instance: "",
endpoint: { id: "", value: "", label: "" }, endpoint: "",
}); });
getSelectors(); getSelectors();
@ -127,14 +127,7 @@ async function getSelectors() {
if (!state.currentLayer) { if (!state.currentLayer) {
return; return;
} }
await getServices(); getServices();
if (!state.service.id) {
queryEvents();
return;
}
getEndpoints();
getInstances();
queryEvents();
} }
async function getServices() { async function getServices() {
@ -143,24 +136,31 @@ async function getServices() {
ElMessage.error(resp.errors); ElMessage.error(resp.errors);
return; return;
} }
state.service = eventStore.services[0]; state.service = eventStore.services[0].value;
if (!eventStore.services[0].id) {
queryEvents();
return;
}
getEndpoints(eventStore.services[0].id);
getInstances(eventStore.services[0].id);
queryEvents();
} }
async function getEndpoints() { async function getEndpoints(id: string) {
const resp = await eventStore.getEndpoints(state.service.id); const resp = await eventStore.getEndpoints(id);
if (resp.errors) { if (resp.errors) {
ElMessage.error(resp.errors); ElMessage.error(resp.errors);
return; return;
} }
state.endpoint = eventStore.endpoints[0]; state.endpoint = eventStore.endpoints[0].value;
} }
async function getInstances() { async function getInstances(id: string) {
const resp = await eventStore.getInstances(state.service.id); const resp = await eventStore.getInstances(id);
if (resp.errors) { if (resp.errors) {
ElMessage.error(resp.errors); ElMessage.error(resp.errors);
return; return;
} }
state.instance = eventStore.instances[0]; state.instance = eventStore.instances[0].value;
} }
async function getLayers() { async function getLayers() {
@ -183,9 +183,9 @@ async function queryEvents() {
needTotal: true, needTotal: true,
}, },
source: { source: {
service: state.service.value || "", service: state.service || "",
endpoint: state.endpoint.value || "", endpoint: state.endpoint || "",
serviceInstance: state.instance.value || "", serviceInstance: state.instance || "",
}, },
type: state.eventType || undefined, type: state.eventType || undefined,
}); });
@ -198,32 +198,31 @@ async function queryEvents() {
async function selectLayer(opt: any) { async function selectLayer(opt: any) {
state.currentLayer = opt[0].value; state.currentLayer = opt[0].value;
await getServices(); await getServices();
if (!state.service.id) {
return;
}
getEndpoints();
getInstances();
} }
function selectService(opt: any) { function selectService(opt: any) {
state.service = opt[0]; state.service = opt[0].value;
if (!state.service.id) { queryEvents();
if (!opt[0].id) {
return; return;
} }
getEndpoints(); getEndpoints(opt[0].id);
getInstances(); getInstances(opt[0].id);
} }
function selectInstance(opt: any) { function selectInstance(opt: any) {
state.instance = opt[0]; state.instance = opt[0].value;
queryEvents();
} }
function selectEndpoint(opt: any) { function selectEndpoint(opt: any) {
state.endpoint = opt[0]; state.endpoint = opt[0].value;
queryEvents();
} }
function selectType(opt: any) { function selectType(opt: any) {
state.eventType = opt[0].value; state.eventType = opt[0].value;
queryEvents();
} }
function updatePage(p: number) { function updatePage(p: number) {