set endpoints

This commit is contained in:
Qiuxia Fan 2022-03-28 17:07:10 +08:00
parent 396315f8f3
commit 10fbf33d5d
6 changed files with 35 additions and 8 deletions

View File

@ -23,6 +23,9 @@ limitations under the License. -->
:disabled="disabled" :disabled="disabled"
:style="{ borderRadius }" :style="{ borderRadius }"
:clearable="clearable" :clearable="clearable"
:remote="isRemote"
:reserve-keyword="isRemote"
:remote-method="remoteMethod"
> >
<el-option <el-option
v-for="item in options" v-for="item in options"
@ -43,7 +46,7 @@ interface Option {
} }
/*global defineProps, defineEmits*/ /*global defineProps, defineEmits*/
const emit = defineEmits(["change"]); const emit = defineEmits(["change", "query"]);
const props = defineProps({ const props = defineProps({
options: { options: {
type: Array as PropType<(Option & { disabled: boolean })[]>, type: Array as PropType<(Option & { disabled: boolean })[]>,
@ -62,6 +65,7 @@ const props = defineProps({
multiple: { type: Boolean, default: false }, multiple: { type: Boolean, default: false },
disabled: { type: Boolean, default: false }, disabled: { type: Boolean, default: false },
clearable: { type: Boolean, default: false }, clearable: { type: Boolean, default: false },
isRemote: { type: Boolean, default: false },
}); });
const selected = ref<string[] | string>(props.value); const selected = ref<string[] | string>(props.value);
@ -73,6 +77,13 @@ function changeSelected() {
); );
emit("change", options); emit("change", options);
} }
function remoteMethod(query: string) {
if (props.isRemote) {
emit("query", query);
}
}
watch( watch(
() => props.value, () => props.value,
(data) => { (data) => {

View File

@ -19,7 +19,7 @@ import TimePicker from "./TimePicker.vue";
import Selector from "./Selector.vue"; import Selector from "./Selector.vue";
import Graph from "./Graph.vue"; import Graph from "./Graph.vue";
import Radio from "./Radio.vue"; import Radio from "./Radio.vue";
import SelectSingle from "./Select.vue"; import SelectSingle from "./SelectSingle.vue";
import type { App } from "vue"; import type { App } from "vue";
import VueGridLayout from "vue-grid-layout"; import VueGridLayout from "vue-grid-layout";

View File

@ -52,7 +52,7 @@ export const Instances = {
export const Endpoints = { export const Endpoints = {
variable: "$serviceId: ID!, $keyword: String!", variable: "$serviceId: ID!, $keyword: String!",
query: ` query: `
pods: findEndpoint(serviceId: $serviceId, keyword: $keyword, limit: 100) { pods: findEndpoint(serviceId: $serviceId, keyword: $keyword, limit: 20) {
id id
value: name value: name
label: name label: name

View File

@ -101,7 +101,6 @@ limitations under the License. -->
@click="controlMenu" @click="controlMenu"
/> />
</div> </div>
<!-- <div class="empty"></div> -->
</div> </div>
</template> </template>

View File

@ -40,7 +40,9 @@ limitations under the License. -->
size="small" size="small"
placeholder="Select a data" placeholder="Select a data"
@change="changePods" @change="changePods"
@query="searchPods"
class="selectorPod" class="selectorPod"
:isRemote="true"
/> />
</div> </div>
<div class="selectors-item" v-if="states.key === 2 || states.key === 4"> <div class="selectors-item" v-if="states.key === 2 || states.key === 4">
@ -126,7 +128,6 @@ const params = useRoute().params;
const toolIcons = ref<{ name: string; content: string; id: string }[]>( const toolIcons = ref<{ name: string; content: string; id: string }[]>(
EndpointRelationTools EndpointRelationTools
); );
const limit = ref<number>(10);
const loading = ref<boolean>(false); const loading = ref<boolean>(false);
const states = reactive<{ const states = reactive<{
destService: string; destService: string;
@ -403,11 +404,16 @@ function setControls(id: string) {
} }
} }
async function fetchPods(type: string, serviceId: string, setPod: boolean) { async function fetchPods(
type: string,
serviceId: string,
setPod: boolean,
param?: { keyword?: string }
) {
let resp; let resp;
switch (type) { switch (type) {
case EntityType[2].value: case EntityType[2].value:
resp = await selectorStore.getEndpoints({ serviceId, limit }); resp = await selectorStore.getEndpoints({ serviceId, ...param });
if (setPod) { if (setPod) {
selectorStore.setCurrentPod( selectorStore.setCurrentPod(
selectorStore.pods.length ? selectorStore.pods[0] : null selectorStore.pods.length ? selectorStore.pods[0] : null
@ -428,7 +434,7 @@ async function fetchPods(type: string, serviceId: string, setPod: boolean) {
resp = await selectorStore.getEndpoints({ resp = await selectorStore.getEndpoints({
serviceId, serviceId,
isRelation: true, isRelation: true,
limit, ...param,
}); });
if (setPod) { if (setPod) {
selectorStore.setCurrentDestPod( selectorStore.setCurrentDestPod(
@ -483,6 +489,17 @@ function getTools() {
toolIcons.value = EndpointRelationTools; toolIcons.value = EndpointRelationTools;
} }
} }
function searchPods(query: string) {
const param = {
keyword: query,
};
fetchPods(
dashboardStore.entity,
selectorStore.currentService.id,
false,
param
);
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.dashboard-tool { .dashboard-tool {