Skip to content

Commit adbfd17

Browse files
authored
Merge pull request #101 from smallerqiu/main
feat: fixed can't get model id and make the model list better presented.
2 parents 1737a37 + 0cc8b2d commit adbfd17

File tree

3 files changed

+88
-39
lines changed

3 files changed

+88
-39
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<template>
2+
<div class="model-list">
3+
<Checkbox
4+
v-for="item in models"
5+
:key="item.value"
6+
:label="item.label"
7+
:checked="checked_models.includes(item.value)"
8+
:value="item.value"
9+
@change="setModel"
10+
/>
11+
</div>
12+
</template>
13+
<script setup>
14+
import { getCurrentInstance } from "vue";
15+
import { message } from "kui-vue";
16+
const { proxy } = getCurrentInstance();
17+
const props = defineProps({
18+
type: String,
19+
group_id: {
20+
type: Number,
21+
},
22+
key_id: {
23+
type: Number,
24+
},
25+
models: {
26+
type: Array,
27+
default: () => [],
28+
},
29+
checked_models: {
30+
type: Array,
31+
default: () => [],
32+
},
33+
});
34+
const updateGroupModel = ({ value }) => {
35+
proxy.$http
36+
.post("/admin/group/bind-or-unbind-model", {
37+
group_id: props.group_id,
38+
model_id: value,
39+
})
40+
.then(() => {
41+
message.success("Updated successfully.");
42+
})
43+
};
44+
const updateApiKeyModel = ({ value }) => {
45+
proxy.$http
46+
.post("/admin/api-key/bind-or-unbind-model", {
47+
key_id: props.key_id,
48+
model_id: value,
49+
})
50+
.then(() => {
51+
message.success("Updated successfully.");
52+
})
53+
};
54+
const setModel = (item) => {
55+
if (props.type === "group") {
56+
updateGroupModel(item);
57+
} else {
58+
updateApiKeyModel(item);
59+
}
60+
};
61+
</script>
62+
<style scoped lang="less">
63+
.model-list {
64+
display: flex;
65+
flex-wrap: wrap;
66+
.k-checkbox {
67+
padding: 8px;
68+
border: 1px solid var(--kui-color-pop-border);
69+
width: 180px;
70+
margin: -1px 0 0 -1px;
71+
}
72+
}
73+
</style>

src-frontend/pages/groups.vue

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,14 @@
5050
v-model="modelsShown"
5151
@ok="modelsShown = false"
5252
:loading="saving"
53+
:width="650"
5354
:mask-closable="true"
5455
>
55-
<CheckboxGroup
56-
:options="models"
57-
v-model="checked_models"
58-
@change="setModel"
56+
<ModelList
57+
:checked_models="checked_models"
58+
:models="models"
59+
:group_id="current_group_id"
60+
type="group"
5961
/>
6062
</Drawer>
6163
</div>
@@ -71,6 +73,7 @@ import {
7173
} from "vue";
7274
import { message } from "kui-vue";
7375
const { proxy } = getCurrentInstance();
76+
import ModelList from "../components/modelList/index.vue";
7477
const $t = inject("$t");
7578
7679
const refForm = ref();
@@ -161,7 +164,7 @@ const listModels = (row) => {
161164
current_group_id.value = row.id;
162165
title.value = $t("group.title_set_models");
163166
// row.loading = true;
164-
proxy.$set(row, "loading", true)
167+
proxy.$set(row, "loading", true);
165168
proxy.$http
166169
.get("/admin/group/list-model", {
167170
group_id: current_group_id.value,
@@ -179,21 +182,6 @@ const listModels = (row) => {
179182
});
180183
};
181184
182-
const setModel = (e) => {
183-
const model_id = e.value;
184-
proxy.$http
185-
.post("/admin/group/bind-or-unbind-model", {
186-
group_id: current_group_id.value,
187-
model_id,
188-
})
189-
.then(() => {
190-
message.success("Save successfully.");
191-
})
192-
.finally(() => {
193-
loading.value = false;
194-
});
195-
};
196-
197185
const add = () => {
198186
action.value = "new";
199187
title.value = $t("keys.btn_new");

src-frontend/pages/keys.vue

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,14 @@
162162
v-model="modelsShown"
163163
@ok="modelsShown = false"
164164
:loading="saving"
165+
:width="650"
165166
:mask-closable="true"
166167
>
167-
<CheckboxGroup
168-
:options="models"
169-
v-model="checked_models"
170-
@change="setModel"
168+
<ModelList
169+
:models="models"
170+
:checked_models="checked_models"
171+
:key_id="current_key_id"
172+
type="api-key"
171173
/>
172174
</Drawer>
173175
</div>
@@ -183,6 +185,7 @@ import {
183185
} from "vue";
184186
import { useClipboard } from "@vueuse/core";
185187
import { Copy, CloudUpload, FolderOpen, Settings } from "kui-icons";
188+
import ModelList from "../components/modelList/index.vue";
186189
import { message, modal } from "kui-vue";
187190
const $t = inject("$t");
188191
const { copy, isSupported } = useClipboard();
@@ -429,21 +432,6 @@ const listModels = (row) => {
429432
});
430433
};
431434
432-
const setModel = (e) => {
433-
const model_id = e.value;
434-
proxy.$http
435-
.post("/admin/api-key/bind-or-unbind-model", {
436-
key_id: current_key_id.value,
437-
model_id,
438-
})
439-
.then(() => {
440-
message.success("Save successfully.");
441-
})
442-
.finally(() => {
443-
loading.value = false;
444-
});
445-
};
446-
447435
const get_data = () => {
448436
loading.value = true;
449437
let {

0 commit comments

Comments
 (0)