refactor: method parameters of api client (#605)

<!--  Thanks for sending a pull request!  Here are some tips for you:
1. 如果这是你的第一次,请阅读我们的贡献指南:<https://github.com/halo-dev/halo/blob/master/CONTRIBUTING.md>。
1. If this is your first time, please read our contributor guidelines: <https://github.com/halo-dev/halo/blob/master/CONTRIBUTING.md>.
2. 请根据你解决问题的类型为 Pull Request 添加合适的标签。
2. Please label this pull request according to what type of issue you are addressing, especially if this is a release targeted pull request.
3. 请确保你已经添加并运行了适当的测试。
3. Ensure you have added or ran the appropriate tests for your PR.
-->

#### What type of PR is this?

/kind improvement
/milestone 2.0

<!--
添加其中一个类别:
Add one of the following kinds:

/kind bug
/kind cleanup
/kind documentation
/kind feature
/kind optimization

适当添加其中一个或多个类别(可选):
Optionally add one or more of the following kinds if applicable:

/kind api-change
/kind deprecation
/kind failing-test
/kind flake
/kind regression
-->

#### What this PR does / why we need it:

修改 api-client 的请求参数结构,改为所有参数由一个对象包裹,而不是将各个参数作为方法的参数,防止因为后端参数结构发生改变,或者生成 api-client 时参数顺序发生改变导致请求异常。如:

```diff
await apiClient.extension.storage.group.updatestorageHaloRunV1alpha1Group(
-        formState.value.metadata.name,
-        formState.value
+        {
+          name: formState.value.metadata.name,
+          group: formState.value,
+        }
      );
```

#### Which issue(s) this PR fixes:

<!--
PR 合并时自动关闭 issue。
Automatically closes linked issue when PR is merged.

用法:`Fixes #<issue 号>`,或者 `Fixes (粘贴 issue 完整链接)`
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
-->
None

#### Screenshots:

<!--
如果此 PR 有 UI 的改动,最好截图说明这个 PR 的改动。
If there are UI changes to this PR, it is best to take a screenshot to illustrate the changes to this PR.

eg.

Before:

![screenshot-before](https://user-images.githubusercontent.com/screenshot.png)

After:

![screenshot-after](https://user-images.githubusercontent.com/screenshot.png)
-->

None

#### Special notes for your reviewer:

/cc @halo-dev/sig-halo-admin 

#### Does this PR introduce a user-facing change?

<!--
如果当前 Pull Request 的修改不会造成用户侧的任何变更,在 `release-note` 代码块儿中填写 `NONE`。
否则请填写用户侧能够理解的 Release Note。如果当前 Pull Request 包含破坏性更新(Break Change),
Release Note 需要以 `action required` 开头。
If no, just write "NONE" in the release-note block below.
If yes, a release note is required:
Enter your extended release note in the block below. If the PR requires additional action from users switching to the new release, include the string "action required".
-->

```release-note
None
```
pull/603/head^2
Ryan Wang 2022-09-06 10:26:11 +08:00 committed by GitHub
parent 3f53680e7b
commit cd33946ca3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
43 changed files with 316 additions and 273 deletions

View File

@ -33,7 +33,7 @@
"@formkit/themes": "1.0.0-beta.10", "@formkit/themes": "1.0.0-beta.10",
"@formkit/vue": "1.0.0-beta.10", "@formkit/vue": "1.0.0-beta.10",
"@halo-dev/admin-shared": "workspace:*", "@halo-dev/admin-shared": "workspace:*",
"@halo-dev/api-client": "^0.0.13", "@halo-dev/api-client": "^0.0.14",
"@halo-dev/components": "workspace:*", "@halo-dev/components": "workspace:*",
"@halo-dev/richtext-editor": "^0.0.0-alpha.5", "@halo-dev/richtext-editor": "^0.0.0-alpha.5",
"@tiptap/extension-character-count": "2.0.0-beta.31", "@tiptap/extension-character-count": "2.0.0-beta.31",

View File

@ -38,7 +38,7 @@
"homepage": "https://github.com/halo-dev/halo-admin/tree/next/shared/components#readme", "homepage": "https://github.com/halo-dev/halo-admin/tree/next/shared/components#readme",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@halo-dev/api-client": "^0.0.13", "@halo-dev/api-client": "^0.0.14",
"@halo-dev/components": "workspace:*", "@halo-dev/components": "workspace:*",
"axios": "^0.27.2" "axios": "^0.27.2"
}, },

View File

@ -46,9 +46,9 @@ export function useSettingForm(
return; return;
} }
try { try {
const response = await apiClient.extension.setting.getv1alpha1Setting( const response = await apiClient.extension.setting.getv1alpha1Setting({
settingName.value name: settingName.value,
); });
settings.value = response.data as FormKitSetting; settings.value = response.data as FormKitSetting;
} catch (e) { } catch (e) {
console.error(e); console.error(e);
@ -63,7 +63,9 @@ export function useSettingForm(
} }
try { try {
const response = await apiClient.extension.configMap.getv1alpha1ConfigMap( const response = await apiClient.extension.configMap.getv1alpha1ConfigMap(
configMapName.value {
name: configMapName.value,
}
); );
configMap.value = response.data; configMap.value = response.data;
@ -105,14 +107,14 @@ export function useSettingForm(
}); });
if (!configMap.value.metadata.creationTimestamp) { if (!configMap.value.metadata.creationTimestamp) {
await apiClient.extension.configMap.createv1alpha1ConfigMap( await apiClient.extension.configMap.createv1alpha1ConfigMap({
configMap.value configMap: configMap.value,
); });
} else { } else {
await apiClient.extension.configMap.updatev1alpha1ConfigMap( await apiClient.extension.configMap.updatev1alpha1ConfigMap({
configMap.value.metadata.name, configMap: configMap.value,
configMap.value name: configMap.value.metadata.name,
); });
} }
} catch (e) { } catch (e) {
console.error(e); console.error(e);

View File

@ -59,9 +59,9 @@ const { settings, handleFetchSettings } = useSettingForm(
const handleFetchPlugin = async () => { const handleFetchPlugin = async () => {
try { try {
const response = const response =
await apiClient.extension.plugin.getpluginHaloRunV1alpha1Plugin( await apiClient.extension.plugin.getpluginHaloRunV1alpha1Plugin({
route.params.name as string name: route.params.name as string,
); });
plugin.value = response.data; plugin.value = response.data;
} catch (e) { } catch (e) {
console.error(e); console.error(e);

View File

@ -13,7 +13,7 @@ importers:
'@formkit/themes': 1.0.0-beta.10 '@formkit/themes': 1.0.0-beta.10
'@formkit/vue': 1.0.0-beta.10 '@formkit/vue': 1.0.0-beta.10
'@halo-dev/admin-shared': workspace:* '@halo-dev/admin-shared': workspace:*
'@halo-dev/api-client': ^0.0.13 '@halo-dev/api-client': ^0.0.14
'@halo-dev/components': workspace:* '@halo-dev/components': workspace:*
'@halo-dev/richtext-editor': ^0.0.0-alpha.5 '@halo-dev/richtext-editor': ^0.0.0-alpha.5
'@iconify-json/vscode-icons': ^1.1.11 '@iconify-json/vscode-icons': ^1.1.11
@ -92,7 +92,7 @@ importers:
'@formkit/themes': 1.0.0-beta.10_tailwindcss@3.1.8 '@formkit/themes': 1.0.0-beta.10_tailwindcss@3.1.8
'@formkit/vue': 1.0.0-beta.10_wwmyxdjqen5bmh3tr2meig5lki '@formkit/vue': 1.0.0-beta.10_wwmyxdjqen5bmh3tr2meig5lki
'@halo-dev/admin-shared': link:packages/shared '@halo-dev/admin-shared': link:packages/shared
'@halo-dev/api-client': 0.0.13 '@halo-dev/api-client': 0.0.14
'@halo-dev/components': link:packages/components '@halo-dev/components': link:packages/components
'@halo-dev/richtext-editor': 0.0.0-alpha.5_vue@3.2.37 '@halo-dev/richtext-editor': 0.0.0-alpha.5_vue@3.2.37
'@tiptap/extension-character-count': 2.0.0-beta.31 '@tiptap/extension-character-count': 2.0.0-beta.31
@ -194,12 +194,12 @@ importers:
packages/shared: packages/shared:
specifiers: specifiers:
'@halo-dev/api-client': ^0.0.13 '@halo-dev/api-client': ^0.0.14
'@halo-dev/components': workspace:* '@halo-dev/components': workspace:*
axios: ^0.27.2 axios: ^0.27.2
vite-plugin-dts: ^1.4.1 vite-plugin-dts: ^1.4.1
dependencies: dependencies:
'@halo-dev/api-client': 0.0.13 '@halo-dev/api-client': 0.0.14
'@halo-dev/components': link:../components '@halo-dev/components': link:../components
axios: 0.27.2 axios: 0.27.2
devDependencies: devDependencies:
@ -2125,8 +2125,8 @@ packages:
- windicss - windicss
dev: false dev: false
/@halo-dev/api-client/0.0.13: /@halo-dev/api-client/0.0.14:
resolution: {integrity: sha512-RP7f8OaB2JS9y6diJpjozhxo/tx5CaQD2FpWj9udoSsWheySR7Tc+wqOMgkhP51xQskhTXRmV9m2pOg6qzFKwA==} resolution: {integrity: sha512-Qh0/l2f5e8lxBgAU2brN28F3CzZTlxGUGY0puUGbuDRYqEENbQ5pGTHG3CzuiG4it4Pn16xSTCXICO6M9m9X4A==}
dev: false dev: false
/@halo-dev/richtext-editor/0.0.0-alpha.5_vue@3.2.37: /@halo-dev/richtext-editor/0.0.0-alpha.5_vue@3.2.37:

View File

@ -164,7 +164,9 @@ async function loadCurrentUser() {
const { data: user } = await apiClient.user.getCurrentUserDetail(); const { data: user } = await apiClient.user.getCurrentUserDetail();
app.provide<User>("currentUser", user); app.provide<User>("currentUser", user);
const { data: currentPermissions } = await apiClient.user.getPermissions("-"); const { data: currentPermissions } = await apiClient.user.getPermissions({
name: "-",
});
const roleStore = useRoleStore(); const roleStore = useRoleStore();
roleStore.$patch({ roleStore.$patch({
permissions: currentPermissions, permissions: currentPermissions,

View File

@ -96,8 +96,10 @@ const handleMove = async (group: Group) => {
name: group.metadata.name, name: group.metadata.name,
}; };
return apiClient.extension.storage.attachment.updatestorageHaloRunV1alpha1Attachment( return apiClient.extension.storage.attachment.updatestorageHaloRunV1alpha1Attachment(
attachment.metadata.name, {
attachmentToUpdate name: attachment.metadata.name,
attachment: attachmentToUpdate,
}
); );
}); });

View File

@ -39,9 +39,9 @@ watchEffect(async () => {
return; return;
} }
const { data } = const { data } =
await apiClient.extension.storage.policy.getstorageHaloRunV1alpha1Policy( await apiClient.extension.storage.policy.getstorageHaloRunV1alpha1Policy({
policyRef.name name: policyRef.name,
); });
policy.value = data; policy.value = data;
} }
}); });

View File

@ -51,12 +51,16 @@ const handleSave = async () => {
saving.value = true; saving.value = true;
if (isUpdateMode.value) { if (isUpdateMode.value) {
await apiClient.extension.storage.group.updatestorageHaloRunV1alpha1Group( await apiClient.extension.storage.group.updatestorageHaloRunV1alpha1Group(
formState.value.metadata.name, {
formState.value name: formState.value.metadata.name,
group: formState.value,
}
); );
} else { } else {
await apiClient.extension.storage.group.createstorageHaloRunV1alpha1Group( await apiClient.extension.storage.group.createstorageHaloRunV1alpha1Group(
formState.value {
group: formState.value,
}
); );
} }
onVisibleChange(false); onVisibleChange(false);

View File

@ -97,12 +97,16 @@ const handleSave = async () => {
if (isUpdateMode.value) { if (isUpdateMode.value) {
await apiClient.extension.storage.policy.updatestorageHaloRunV1alpha1Policy( await apiClient.extension.storage.policy.updatestorageHaloRunV1alpha1Policy(
formState.value.metadata.name, {
formState.value name: formState.value.metadata.name,
policy: formState.value,
}
); );
} else { } else {
await apiClient.extension.storage.policy.createstorageHaloRunV1alpha1Policy( await apiClient.extension.storage.policy.createstorageHaloRunV1alpha1Policy(
formState.value {
policy: formState.value,
}
); );
} }
@ -151,7 +155,9 @@ watch(
if (formState.value.spec.templateRef?.name) { if (formState.value.spec.templateRef?.name) {
const { data } = const { data } =
await apiClient.extension.storage.policyTemplate.getstorageHaloRunV1alpha1PolicyTemplate( await apiClient.extension.storage.policyTemplate.getstorageHaloRunV1alpha1PolicyTemplate(
formState.value.spec.templateRef.name {
name: formState.value.spec.templateRef.name,
}
); );
policyTemplate.value = data; policyTemplate.value = data;
} }

View File

@ -54,9 +54,11 @@ const onVisibleChange = (visible: boolean) => {
const uploadHandler = computed(() => { const uploadHandler = computed(() => {
return (file, config) => return (file, config) =>
apiClient.extension.storage.attachment.uploadAttachment( apiClient.extension.storage.attachment.uploadAttachment(
file, {
selectedPolicy.value?.metadata.name as string, file,
props.group?.metadata.name as string, policyName: selectedPolicy.value?.metadata.name as string,
groupName: props.group?.metadata.name as string,
},
config config
); );
}); });

View File

@ -71,9 +71,11 @@ const selectedAttachments = ref<Set<Attachment>>(new Set<Attachment>());
const uploadHandler = computed(() => { const uploadHandler = computed(() => {
return (file, config) => return (file, config) =>
apiClient.extension.storage.attachment.uploadAttachment( apiClient.extension.storage.attachment.uploadAttachment(
file, {
selectedPolicy.value, file,
selectedGroup.value, policyName: selectedPolicy.value,
groupName: selectedGroup.value,
},
config config
); );
}); });
@ -83,7 +85,9 @@ const onUploaded = async (response: AxiosResponse) => {
const { data } = const { data } =
await apiClient.extension.storage.attachment.getstorageHaloRunV1alpha1Attachment( await apiClient.extension.storage.attachment.getstorageHaloRunV1alpha1Attachment(
attachment.metadata.name {
name: attachment.metadata.name,
}
); );
attachments.value.add(data); attachments.value.add(data);
selectedAttachments.value.add(data); selectedAttachments.value.add(data);
@ -107,7 +111,9 @@ const handleDelete = async (attachment: Attachment) => {
onConfirm: async () => { onConfirm: async () => {
try { try {
await apiClient.extension.storage.attachment.deletestorageHaloRunV1alpha1Attachment( await apiClient.extension.storage.attachment.deletestorageHaloRunV1alpha1Attachment(
attachment.metadata.name {
name: attachment.metadata.name,
}
); );
attachments.value.delete(attachment); attachments.value.delete(attachment);
selectedAttachments.value.delete(attachment); selectedAttachments.value.delete(attachment);

View File

@ -63,16 +63,14 @@ export function useAttachmentControl(filterOptions?: {
try { try {
loading.value = true; loading.value = true;
const { data } = const { data } =
await apiClient.extension.storage.attachment.searchAttachments( await apiClient.extension.storage.attachment.searchAttachments({
policy?.value?.metadata.name, policy: policy?.value?.metadata.name,
keyword?.value, displayName: keyword?.value,
group?.value?.metadata.name, group: group?.value?.metadata.name,
user?.value?.metadata.name, uploadedBy: user?.value?.metadata.name,
attachments.value.size, page: attachments.value.page,
attachments.value.page, size: attachments.value.size,
[], });
[]
);
attachments.value = data; attachments.value = data;
} catch (e) { } catch (e) {
console.error("Failed to fetch attachments", e); console.error("Failed to fetch attachments", e);
@ -138,7 +136,9 @@ export function useAttachmentControl(filterOptions?: {
const promises = Array.from(selectedAttachments.value).map( const promises = Array.from(selectedAttachments.value).map(
(attachment) => { (attachment) => {
return apiClient.extension.storage.attachment.deletestorageHaloRunV1alpha1Attachment( return apiClient.extension.storage.attachment.deletestorageHaloRunV1alpha1Attachment(
attachment.metadata.name {
name: attachment.metadata.name,
}
); );
} }
); );

View File

@ -155,13 +155,15 @@ const handleSave = async () => {
} }
if (isUpdateMode.value) { if (isUpdateMode.value) {
const { data } = await apiClient.post.updateDraftPost( const { data } = await apiClient.post.updateDraftPost({
formState.value.post.metadata.name, name: formState.value.post.metadata.name,
formState.value postRequest: formState.value,
); });
formState.value.post = data; formState.value.post = data;
} else { } else {
const { data } = await apiClient.post.draftPost(formState.value); const { data } = await apiClient.post.draftPost({
postRequest: formState.value,
});
formState.value.post = data; formState.value.post = data;
name.value = data.metadata.name; name.value = data.metadata.name;
} }
@ -178,9 +180,9 @@ const handleFetchContent = async () => {
if (!formState.value.post.spec.headSnapshot) { if (!formState.value.post.spec.headSnapshot) {
return; return;
} }
const { data } = await apiClient.content.obtainSnapshotContent( const { data } = await apiClient.content.obtainSnapshotContent({
formState.value.post.spec.headSnapshot snapshotName: formState.value.post.spec.headSnapshot,
); });
formState.value.content = data; formState.value.content = data;
}; };
@ -201,9 +203,9 @@ onMounted(async () => {
if (name.value) { if (name.value) {
// fetch post // fetch post
const { data: post } = const { data: post } =
await apiClient.extension.post.getcontentHaloRunV1alpha1Post( await apiClient.extension.post.getcontentHaloRunV1alpha1Post({
name.value as string name: name.value as string,
); });
formState.value.post = post; formState.value.post = post;
// fetch post content // fetch post content

View File

@ -76,11 +76,11 @@ const handleFetchPosts = async () => {
); );
} }
const { data } = await apiClient.post.listPosts( const { data } = await apiClient.post.listPosts({
posts.value.page, page: posts.value.page,
posts.value.size, size: posts.value.size,
labelSelector labelSelector,
); });
posts.value = data; posts.value = data;
} catch (e) { } catch (e) {
console.error("Failed to fetch posts", e); console.error("Failed to fetch posts", e);
@ -103,7 +103,9 @@ const handlePaginationChange = ({
const handleOpenSettingModal = async (post: Post) => { const handleOpenSettingModal = async (post: Post) => {
const { data } = await apiClient.extension.post.getcontentHaloRunV1alpha1Post( const { data } = await apiClient.extension.post.getcontentHaloRunV1alpha1Post(
post.metadata.name {
name: post.metadata.name,
}
); );
selectedPost.value = data; selectedPost.value = data;
settingModal.value = true; settingModal.value = true;
@ -122,9 +124,9 @@ const handleSelectPrevious = async () => {
); );
if (index > 0) { if (index > 0) {
const { data } = const { data } =
await apiClient.extension.post.getcontentHaloRunV1alpha1Post( await apiClient.extension.post.getcontentHaloRunV1alpha1Post({
items[index - 1].post.metadata.name name: items[index - 1].post.metadata.name,
); });
selectedPost.value = data; selectedPost.value = data;
return; return;
} }
@ -142,9 +144,9 @@ const handleSelectNext = async () => {
); );
if (index < items.length - 1) { if (index < items.length - 1) {
const { data } = const { data } =
await apiClient.extension.post.getcontentHaloRunV1alpha1Post( await apiClient.extension.post.getcontentHaloRunV1alpha1Post({
items[index + 1].post.metadata.name name: items[index + 1].post.metadata.name,
); });
selectedPost.value = data; selectedPost.value = data;
return; return;
} }
@ -189,10 +191,10 @@ const handleDelete = async (post: Post) => {
onConfirm: async () => { onConfirm: async () => {
const postToUpdate = cloneDeep(post); const postToUpdate = cloneDeep(post);
postToUpdate.spec.deleted = true; postToUpdate.spec.deleted = true;
await apiClient.extension.post.updatecontentHaloRunV1alpha1Post( await apiClient.extension.post.updatecontentHaloRunV1alpha1Post({
postToUpdate.metadata.name, name: postToUpdate.metadata.name,
postToUpdate post: postToUpdate,
); });
await handleFetchPosts(); await handleFetchPosts();
}, },
}); });
@ -207,9 +209,9 @@ watchEffect(async () => {
return; return;
} }
const { data: content } = await apiClient.content.obtainSnapshotContent( const { data: content } = await apiClient.content.obtainSnapshotContent({
selectedPost.value.spec.headSnapshot snapshotName: selectedPost.value.spec.headSnapshot,
); });
selectedPostWithContent.value = { selectedPostWithContent.value = {
post: selectedPost.value, post: selectedPost.value,

View File

@ -49,10 +49,10 @@ const handleUpdateInBatch = useDebounceFn(async () => {
const categoriesToUpdate = convertTreeToCategories(categoriesTreeToUpdate); const categoriesToUpdate = convertTreeToCategories(categoriesTreeToUpdate);
try { try {
const promises = categoriesToUpdate.map((category) => const promises = categoriesToUpdate.map((category) =>
apiClient.extension.category.updatecontentHaloRunV1alpha1Category( apiClient.extension.category.updatecontentHaloRunV1alpha1Category({
category.metadata.name, name: category.metadata.name,
category category: category,
) })
); );
await Promise.all(promises); await Promise.all(promises);
} catch (e) { } catch (e) {

View File

@ -64,14 +64,14 @@ const handleSaveCategory = async () => {
try { try {
saving.value = true; saving.value = true;
if (isUpdateMode.value) { if (isUpdateMode.value) {
await apiClient.extension.category.updatecontentHaloRunV1alpha1Category( await apiClient.extension.category.updatecontentHaloRunV1alpha1Category({
formState.value.metadata.name, name: formState.value.metadata.name,
formState.value category: formState.value,
); });
} else { } else {
await apiClient.extension.category.createcontentHaloRunV1alpha1Category( await apiClient.extension.category.createcontentHaloRunV1alpha1Category({
formState.value category: formState.value,
); });
} }
onVisibleChange(false); onVisibleChange(false);
} catch (e) { } catch (e) {

View File

@ -25,10 +25,10 @@ export function usePostCategory(): usePostCategoryReturn {
try { try {
loading.value = true; loading.value = true;
const { data } = const { data } =
await apiClient.extension.category.listcontentHaloRunV1alpha1Category( await apiClient.extension.category.listcontentHaloRunV1alpha1Category({
0, page: 0,
0 size: 0,
); });
categories.value = data.items; categories.value = data.items;
categoriesTree.value = buildCategoriesTree(data.items); categoriesTree.value = buildCategoriesTree(data.items);
} catch (e) { } catch (e) {
@ -46,7 +46,9 @@ export function usePostCategory(): usePostCategoryReturn {
onConfirm: async () => { onConfirm: async () => {
try { try {
await apiClient.extension.category.deletecontentHaloRunV1alpha1Category( await apiClient.extension.category.deletecontentHaloRunV1alpha1Category(
category.metadata.name {
name: category.metadata.name,
}
); );
} catch (e) { } catch (e) {
console.error("Failed to delete tag", e); console.error("Failed to delete tag", e);

View File

@ -106,14 +106,16 @@ const handleSave = async () => {
formState.value.content.content = formState.value.content.raw; formState.value.content.content = formState.value.content.raw;
if (isUpdateMode.value) { if (isUpdateMode.value) {
const { data } = await apiClient.post.updateDraftPost( const { data } = await apiClient.post.updateDraftPost({
formState.value.post.metadata.name, name: formState.value.post.metadata.name,
formState.value postRequest: formState.value,
); });
formState.value.post = data; formState.value.post = data;
emit("saved", formState.value); emit("saved", formState.value);
} else { } else {
const { data } = await apiClient.post.draftPost(formState.value); const { data } = await apiClient.post.draftPost({
postRequest: formState.value,
});
formState.value.post = data; formState.value.post = data;
emit("saved", formState.value); emit("saved", formState.value);
} }
@ -133,15 +135,15 @@ const handlePublish = async () => {
// Get latest version post // Get latest version post
const { data: latestData } = const { data: latestData } =
await apiClient.extension.post.getcontentHaloRunV1alpha1Post( await apiClient.extension.post.getcontentHaloRunV1alpha1Post({
formState.value.post.metadata.name name: formState.value.post.metadata.name,
); });
formState.value.post = latestData; formState.value.post = latestData;
// Publish post // Publish post
const { data } = await apiClient.post.publishPost( const { data } = await apiClient.post.publishPost({
formState.value.post.metadata.name name: formState.value.post.metadata.name,
); });
formState.value.post = data; formState.value.post = data;
emit("saved", formState.value); emit("saved", formState.value);
} catch (e) { } catch (e) {
@ -158,16 +160,16 @@ const handlePublishCanceling = async () => {
// Update published spec = false // Update published spec = false
const postToUpdate = cloneDeep(formState.value); const postToUpdate = cloneDeep(formState.value);
postToUpdate.post.spec.published = false; postToUpdate.post.spec.published = false;
await apiClient.post.updateDraftPost( await apiClient.post.updateDraftPost({
postToUpdate.post.metadata.name, name: postToUpdate.post.metadata.name,
postToUpdate postRequest: postToUpdate,
); });
// Get latest version post // Get latest version post
const { data: latestData } = const { data: latestData } =
await apiClient.extension.post.getcontentHaloRunV1alpha1Post( await apiClient.extension.post.getcontentHaloRunV1alpha1Post({
formState.value.post.metadata.name name: formState.value.post.metadata.name,
); });
formState.value.post = latestData; formState.value.post = latestData;
emit("saved", formState.value); emit("saved", formState.value);

View File

@ -89,7 +89,9 @@ const queryName = useRouteQuery("name");
onMounted(async () => { onMounted(async () => {
if (queryName.value) { if (queryName.value) {
const { data } = await apiClient.extension.tag.getcontentHaloRunV1alpha1Tag( const { data } = await apiClient.extension.tag.getcontentHaloRunV1alpha1Tag(
queryName.value as string {
name: queryName.value as string,
}
); );
selectedTag.value = data; selectedTag.value = data;
editingModal.value = true; editingModal.value = true;

View File

@ -68,14 +68,14 @@ const handleSaveTag = async () => {
try { try {
saving.value = true; saving.value = true;
if (isUpdateMode.value) { if (isUpdateMode.value) {
await apiClient.extension.tag.updatecontentHaloRunV1alpha1Tag( await apiClient.extension.tag.updatecontentHaloRunV1alpha1Tag({
formState.value.metadata.name, name: formState.value.metadata.name,
formState.value tag: formState.value,
); });
} else { } else {
await apiClient.extension.tag.createcontentHaloRunV1alpha1Tag( await apiClient.extension.tag.createcontentHaloRunV1alpha1Tag({
formState.value tag: formState.value,
); });
} }
onVisibleChange(false); onVisibleChange(false);
} catch (e) { } catch (e) {

View File

@ -21,7 +21,10 @@ export function usePostTag(): usePostTagReturn {
try { try {
loading.value = true; loading.value = true;
const { data } = const { data } =
await apiClient.extension.tag.listcontentHaloRunV1alpha1Tag(0, 0); await apiClient.extension.tag.listcontentHaloRunV1alpha1Tag({
page: 0,
size: 0,
});
tags.value = data.items; tags.value = data.items;
} catch (e) { } catch (e) {
@ -38,9 +41,9 @@ export function usePostTag(): usePostTagReturn {
confirmType: "danger", confirmType: "danger",
onConfirm: async () => { onConfirm: async () => {
try { try {
await apiClient.extension.tag.deletecontentHaloRunV1alpha1Tag( await apiClient.extension.tag.deletecontentHaloRunV1alpha1Tag({
tag.metadata.name name: tag.metadata.name,
); });
} catch (e) { } catch (e) {
console.error("Failed to delete tag", e); console.error("Failed to delete tag", e);
} finally { } finally {

View File

@ -46,12 +46,11 @@ const handleFetchMenuItems = async () => {
const menuItemNames = Array.from(selectedMenu.value.spec.menuItems)?.map( const menuItemNames = Array.from(selectedMenu.value.spec.menuItems)?.map(
(item) => item (item) => item
); );
const { data } = await apiClient.extension.menuItem.listv1alpha1MenuItem( const { data } = await apiClient.extension.menuItem.listv1alpha1MenuItem({
0, page: 0,
0, size: 0,
[], fieldSelector: [`name=(${menuItemNames.join(",")})`],
[`name=(${menuItemNames.join(",")})`] });
);
menuItems.value = data.items; menuItems.value = data.items;
// Build the menu tree // Build the menu tree
menuTreeItems.value = buildMenuItemsTree(data.items); menuTreeItems.value = buildMenuItemsTree(data.items);
@ -71,17 +70,14 @@ const onMenuItemSaved = async (menuItem: MenuItem) => {
const menuToUpdate = cloneDeep(selectedMenu.value); const menuToUpdate = cloneDeep(selectedMenu.value);
if (menuToUpdate) { if (menuToUpdate) {
const menuItemsToUpdate = Array.from( const menuItemsToUpdate = cloneDeep(menuToUpdate.spec.menuItems) || [];
cloneDeep(menuToUpdate.spec.menuItems) || new Set<string>()
);
menuItemsToUpdate.push(menuItem.metadata.name); menuItemsToUpdate.push(menuItem.metadata.name);
// @ts-ignore menuToUpdate.spec.menuItems = menuItemsToUpdate;
menuToUpdate.spec.menuItems = Array.from(new Set(menuItemsToUpdate)); await apiClient.extension.menu.updatev1alpha1Menu({
await apiClient.extension.menu.updatev1alpha1Menu( name: menuToUpdate.metadata.name,
menuToUpdate.metadata.name, menu: menuToUpdate,
menuToUpdate });
);
} }
await menuListRef.value.handleFetchMenus(); await menuListRef.value.handleFetchMenus();
@ -93,10 +89,10 @@ const handleUpdateInBatch = useDebounceFn(async () => {
const menuItemsToUpdate = convertTreeToMenuItems(menuTreeItemsToUpdate); const menuItemsToUpdate = convertTreeToMenuItems(menuTreeItemsToUpdate);
try { try {
const promises = menuItemsToUpdate.map((menuItem) => const promises = menuItemsToUpdate.map((menuItem) =>
apiClient.extension.menuItem.updatev1alpha1MenuItem( apiClient.extension.menuItem.updatev1alpha1MenuItem({
menuItem.metadata.name, name: menuItem.metadata.name,
menuItem menuItem,
) })
); );
await Promise.all(promises); await Promise.all(promises);
} catch (e) { } catch (e) {
@ -113,9 +109,9 @@ const handleDelete = async (menuItem: MenuTreeItem) => {
description: "删除后将无法恢复", description: "删除后将无法恢复",
confirmType: "danger", confirmType: "danger",
onConfirm: async () => { onConfirm: async () => {
await apiClient.extension.menuItem.deletev1alpha1MenuItem( await apiClient.extension.menuItem.deletev1alpha1MenuItem({
menuItem.metadata.name name: menuItem.metadata.name,
); });
const childrenNames = getChildrenNames(menuItem); const childrenNames = getChildrenNames(menuItem);
@ -127,7 +123,9 @@ const handleDelete = async (menuItem: MenuTreeItem) => {
confirmType: "danger", confirmType: "danger",
onConfirm: async () => { onConfirm: async () => {
const promises = childrenNames.map((name) => const promises = childrenNames.map((name) =>
apiClient.extension.menuItem.deletev1alpha1MenuItem(name) apiClient.extension.menuItem.deletev1alpha1MenuItem({
name,
})
); );
await Promise.all(promises); await Promise.all(promises);
}, },

View File

@ -28,7 +28,6 @@ const emit = defineEmits<{
const initialFormState: Menu = { const initialFormState: Menu = {
spec: { spec: {
displayName: "", displayName: "",
// @ts-ignore
menuItems: [], menuItems: [],
}, },
apiVersion: "v1alpha1", apiVersion: "v1alpha1",
@ -49,14 +48,14 @@ const handleCreateMenu = async () => {
try { try {
saving.value = true; saving.value = true;
if (isUpdateMode.value) { if (isUpdateMode.value) {
await apiClient.extension.menu.updatev1alpha1Menu( await apiClient.extension.menu.updatev1alpha1Menu({
formState.value.metadata.name, name: formState.value.metadata.name,
formState.value menu: formState.value,
); });
} else { } else {
const { data } = await apiClient.extension.menu.createv1alpha1Menu( const { data } = await apiClient.extension.menu.createv1alpha1Menu({
formState.value menu: formState.value,
); });
emit("created", data); emit("created", data);
} }
onVisibleChange(false); onVisibleChange(false);

View File

@ -29,7 +29,7 @@ const initialFormState: MenuItem = {
spec: { spec: {
displayName: "", displayName: "",
href: "", href: "",
children: new Set([]), children: [],
priority: 0, priority: 0,
}, },
apiVersion: "v1alpha1", apiVersion: "v1alpha1",
@ -50,23 +50,19 @@ const handleSaveMenuItem = async () => {
try { try {
saving.value = true; saving.value = true;
// TODO Array
// @ts-ignore
formState.value.spec.children = Array.from(formState.value.spec.children);
if (isUpdateMode.value) { if (isUpdateMode.value) {
const { data } = const { data } =
await apiClient.extension.menuItem.updatev1alpha1MenuItem( await apiClient.extension.menuItem.updatev1alpha1MenuItem({
formState.value.metadata.name, name: formState.value.metadata.name,
formState.value menuItem: formState.value,
); });
onVisibleChange(false); onVisibleChange(false);
emit("saved", data); emit("saved", data);
} else { } else {
const { data } = const { data } =
await apiClient.extension.menuItem.createv1alpha1MenuItem( await apiClient.extension.menuItem.createv1alpha1MenuItem({
formState.value menuItem: formState.value,
); });
onVisibleChange(false); onVisibleChange(false);
emit("saved", data); emit("saved", data);
} }

View File

@ -72,10 +72,15 @@ const handleDeleteMenu = async (menu: Menu) => {
confirmType: "danger", confirmType: "danger",
onConfirm: async () => { onConfirm: async () => {
try { try {
await apiClient.extension.menu.deletev1alpha1Menu(menu.metadata.name); await apiClient.extension.menu.deletev1alpha1Menu({
name: menu.metadata.name,
});
const deleteItemsPromises = Array.from(menu.spec.menuItems || []).map( const deleteItemsPromises = Array.from(menu.spec.menuItems || []).map(
(item) => apiClient.extension.menuItem.deletev1alpha1MenuItem(item) (item) =>
apiClient.extension.menuItem.deletev1alpha1MenuItem({
name: item,
})
); );
await Promise.all(deleteItemsPromises); await Promise.all(deleteItemsPromises);
@ -151,7 +156,7 @@ defineExpose({
{{ menu.spec?.displayName }} {{ menu.spec?.displayName }}
</span> </span>
<span class="block text-xs text-gray-400"> <span class="block text-xs text-gray-400">
{{ Array.from(menu.spec.menuItems || new Set()).length }} {{ menu.spec.menuItems?.length || 0 }}
个菜单项 个菜单项
</span> </span>
</span> </span>

View File

@ -92,10 +92,10 @@ exports[`convertMenuTreeItemToMenuItem > should match snapshot 1`] = `
"version": 12, "version": 12,
}, },
"spec": { "spec": {
"children": Set { "children": [
"caeef383-3828-4039-9114-6f9ad3b4a37e", "caeef383-3828-4039-9114-6f9ad3b4a37e",
"ded1943d-9fdb-4563-83ee-2f04364872e0", "ded1943d-9fdb-4563-83ee-2f04364872e0",
}, ],
"displayName": "文章分类", "displayName": "文章分类",
"href": "https://ryanc.cc/categories", "href": "https://ryanc.cc/categories",
"priority": 1, "priority": 1,
@ -113,9 +113,9 @@ exports[`convertMenuTreeItemToMenuItem > should match snapshot 2`] = `
"version": 1, "version": 1,
}, },
"spec": { "spec": {
"children": Set { "children": [
"96b636bb-3e4a-44d1-8ea7-f9da9e876f45", "96b636bb-3e4a-44d1-8ea7-f9da9e876f45",
}, ],
"displayName": "Java", "displayName": "Java",
"href": "https://ryanc.cc/categories/java", "href": "https://ryanc.cc/categories/java",
"priority": 1, "priority": 1,

View File

@ -15,7 +15,6 @@ const rawMenuItems: MenuItem[] = [
spec: { spec: {
displayName: "文章分类", displayName: "文章分类",
href: "https://ryanc.cc/categories", href: "https://ryanc.cc/categories",
// @ts-ignore
children: [ children: [
"caeef383-3828-4039-9114-6f9ad3b4a37e", "caeef383-3828-4039-9114-6f9ad3b4a37e",
"ded1943d-9fdb-4563-83ee-2f04364872e0", "ded1943d-9fdb-4563-83ee-2f04364872e0",
@ -34,7 +33,6 @@ const rawMenuItems: MenuItem[] = [
spec: { spec: {
displayName: "Halo", displayName: "Halo",
href: "https://ryanc.cc/categories/halo", href: "https://ryanc.cc/categories/halo",
// @ts-ignore
children: [], children: [],
priority: 0, priority: 0,
}, },
@ -50,7 +48,6 @@ const rawMenuItems: MenuItem[] = [
spec: { spec: {
displayName: "Java", displayName: "Java",
href: "https://ryanc.cc/categories/java", href: "https://ryanc.cc/categories/java",
// @ts-ignore
children: ["96b636bb-3e4a-44d1-8ea7-f9da9e876f45"], children: ["96b636bb-3e4a-44d1-8ea7-f9da9e876f45"],
priority: 1, priority: 1,
}, },
@ -66,7 +63,6 @@ const rawMenuItems: MenuItem[] = [
spec: { spec: {
displayName: "Spring Boot", displayName: "Spring Boot",
href: "https://ryanc.cc/categories/spring-boot", href: "https://ryanc.cc/categories/spring-boot",
// @ts-ignore
children: [], children: [],
priority: 0, priority: 0,
}, },
@ -82,7 +78,6 @@ const rawMenuItems: MenuItem[] = [
spec: { spec: {
displayName: "首页", displayName: "首页",
href: "https://ryanc.cc/", href: "https://ryanc.cc/",
// @ts-ignore
children: [], children: [],
priority: 0, priority: 0,
}, },
@ -259,11 +254,9 @@ describe("convertMenuTreeItemToMenuItem", () => {
).toBe("文章分类"); ).toBe("文章分类");
expect( expect(
convertMenuTreeItemToMenuItem(menuTreeItems[1]).spec.children convertMenuTreeItemToMenuItem(menuTreeItems[1]).spec.children
).toStrictEqual( ).toStrictEqual([
new Set([ "caeef383-3828-4039-9114-6f9ad3b4a37e",
"caeef383-3828-4039-9114-6f9ad3b4a37e", "ded1943d-9fdb-4563-83ee-2f04364872e0",
"ded1943d-9fdb-4563-83ee-2f04364872e0", ]);
])
);
}); });
}); });

View File

@ -128,7 +128,6 @@ export function buildMenuItemsTree(menuItems: MenuItem[]): MenuTreeItem[] {
menuItem.spec.children.forEach((child) => { menuItem.spec.children.forEach((child) => {
parentMap[child] = menuItem.metadata.name; parentMap[child] = menuItem.metadata.name;
}); });
// @ts-ignore
menuItem.spec.children = []; menuItem.spec.children = [];
}); });
@ -212,7 +211,6 @@ export function convertTreeToMenuItems(menuTreeItems: MenuTreeItem[]) {
...node, ...node,
spec: { spec: {
...node.spec, ...node.spec,
// @ts-ignore
children: children.map((child) => child.metadata.name), children: children.map((child) => child.metadata.name),
}, },
}); });
@ -261,7 +259,7 @@ export function convertMenuTreeItemToMenuItem(
...menuTreeItem, ...menuTreeItem,
spec: { spec: {
...menuTreeItem.spec, ...menuTreeItem.spec,
children: new Set(childNames), children: childNames,
}, },
}; };
} }

View File

@ -59,9 +59,9 @@ const handleUninstall = async (theme: Theme) => {
description: "删除后将无法恢复。", description: "删除后将无法恢复。",
onConfirm: async () => { onConfirm: async () => {
try { try {
await apiClient.extension.theme.deletethemeHaloRunV1alpha1Theme( await apiClient.extension.theme.deletethemeHaloRunV1alpha1Theme({
theme.metadata.name name: theme.metadata.name,
); });
} catch (e) { } catch (e) {
console.error("Failed to uninstall theme", e); console.error("Failed to uninstall theme", e);
} finally { } finally {

View File

@ -26,7 +26,9 @@ export function useThemeLifeCycle(theme: Ref<Theme>): useThemeLifeCycleReturn {
loading.value = true; loading.value = true;
const { data } = await apiClient.extension.configMap.getv1alpha1ConfigMap( const { data } = await apiClient.extension.configMap.getv1alpha1ConfigMap(
"system" {
name: "system",
}
); );
if (!data.data?.theme) { if (!data.data?.theme) {
@ -36,9 +38,9 @@ export function useThemeLifeCycle(theme: Ref<Theme>): useThemeLifeCycleReturn {
const themeConfig = JSON.parse(data.data.theme); const themeConfig = JSON.parse(data.data.theme);
const { data: themeData } = const { data: themeData } =
await apiClient.extension.theme.getthemeHaloRunV1alpha1Theme( await apiClient.extension.theme.getthemeHaloRunV1alpha1Theme({
themeConfig.active name: themeConfig.active,
); });
theme.value = themeData; theme.value = themeData;
activatedTheme.value = themeData; activatedTheme.value = themeData;
@ -56,7 +58,9 @@ export function useThemeLifeCycle(theme: Ref<Theme>): useThemeLifeCycleReturn {
onConfirm: async () => { onConfirm: async () => {
try { try {
const { data: systemConfigMap } = const { data: systemConfigMap } =
await apiClient.extension.configMap.getv1alpha1ConfigMap("system"); await apiClient.extension.configMap.getv1alpha1ConfigMap({
name: "system",
});
if (systemConfigMap.data) { if (systemConfigMap.data) {
const themeConfigToUpdate = JSON.parse( const themeConfigToUpdate = JSON.parse(
@ -65,10 +69,10 @@ export function useThemeLifeCycle(theme: Ref<Theme>): useThemeLifeCycleReturn {
themeConfigToUpdate.active = theme.value?.metadata?.name; themeConfigToUpdate.active = theme.value?.metadata?.name;
systemConfigMap.data["theme"] = JSON.stringify(themeConfigToUpdate); systemConfigMap.data["theme"] = JSON.stringify(themeConfigToUpdate);
await apiClient.extension.configMap.updatev1alpha1ConfigMap( await apiClient.extension.configMap.updatev1alpha1ConfigMap({
"system", name: "system",
systemConfigMap configMap: systemConfigMap,
); });
} }
} catch (e) { } catch (e) {
console.error("Failed to active theme", e); console.error("Failed to active theme", e);

View File

@ -20,9 +20,11 @@ const pluginRoleTemplates = ref<Role[]>([]);
const handleFetchRoles = async () => { const handleFetchRoles = async () => {
try { try {
const { data } = await apiClient.extension.role.listv1alpha1Role(0, 0, [ const { data } = await apiClient.extension.role.listv1alpha1Role({
`${pluginLabels.NAME}=${plugin.value.metadata.name}`, page: 0,
]); size: 0,
labelSelector: [`${pluginLabels.NAME}=${plugin.value.metadata.name}`],
});
pluginRoleTemplates.value = data.items; pluginRoleTemplates.value = data.items;
} catch (e) { } catch (e) {
console.error(e); console.error(e);

View File

@ -33,12 +33,11 @@ const handleFetchPlugins = async () => {
} }
const { data } = const { data } =
await apiClient.extension.plugin.listpluginHaloRunV1alpha1Plugin( await apiClient.extension.plugin.listpluginHaloRunV1alpha1Plugin({
0, page: 0,
0, size: 0,
[], fieldSelector,
fieldSelector });
);
plugins.value = data.items; plugins.value = data.items;
} catch (e) { } catch (e) {
console.error("Fail to fetch plugins", e); console.error("Fail to fetch plugins", e);

View File

@ -48,15 +48,15 @@ const server = {
onConfirm: async () => { onConfirm: async () => {
try { try {
const { data: pluginToUpdate } = const { data: pluginToUpdate } =
await apiClient.extension.plugin.getpluginHaloRunV1alpha1Plugin( await apiClient.extension.plugin.getpluginHaloRunV1alpha1Plugin({
plugin.metadata.name name: plugin.metadata.name,
); });
pluginToUpdate.spec.enabled = true; pluginToUpdate.spec.enabled = true;
await apiClient.extension.plugin.updatepluginHaloRunV1alpha1Plugin( await apiClient.extension.plugin.updatepluginHaloRunV1alpha1Plugin({
pluginToUpdate.metadata.name, name: pluginToUpdate.metadata.name,
pluginToUpdate plugin: pluginToUpdate,
); });
window.location.reload(); window.location.reload();
} catch (e) { } catch (e) {

View File

@ -32,10 +32,10 @@ export function usePluginLifeCycle(
onConfirm: async () => { onConfirm: async () => {
try { try {
pluginToUpdate.spec.enabled = !pluginToUpdate.spec.enabled; pluginToUpdate.spec.enabled = !pluginToUpdate.spec.enabled;
await apiClient.extension.plugin.updatepluginHaloRunV1alpha1Plugin( await apiClient.extension.plugin.updatepluginHaloRunV1alpha1Plugin({
pluginToUpdate.metadata.name, name: pluginToUpdate.metadata.name,
pluginToUpdate plugin: pluginToUpdate,
); });
} catch (e) { } catch (e) {
console.error(e); console.error(e);
} finally { } finally {
@ -64,15 +64,15 @@ export function usePluginLifeCycle(
if (enabled) { if (enabled) {
const pluginToUpdate = cloneDeep(plugin.value); const pluginToUpdate = cloneDeep(plugin.value);
pluginToUpdate.spec.enabled = false; pluginToUpdate.spec.enabled = false;
await apiClient.extension.plugin.updatepluginHaloRunV1alpha1Plugin( await apiClient.extension.plugin.updatepluginHaloRunV1alpha1Plugin({
pluginToUpdate.metadata.name, name: pluginToUpdate.metadata.name,
pluginToUpdate plugin: pluginToUpdate,
); });
} }
await apiClient.extension.plugin.deletepluginHaloRunV1alpha1Plugin( await apiClient.extension.plugin.deletepluginHaloRunV1alpha1Plugin({
plugin.value.metadata.name name: plugin.value.metadata.name,
); });
} catch (e) { } catch (e) {
console.error(e); console.error(e);
} finally { } finally {

View File

@ -42,9 +42,9 @@ watch(
const handleFetchRole = async () => { const handleFetchRole = async () => {
try { try {
const response = await apiClient.extension.role.getv1alpha1Role( const response = await apiClient.extension.role.getv1alpha1Role({
route.params.name as string name: route.params.name as string,
); });
formState.value = response.data; formState.value = response.data;
selectedRoleTemplates.value = new Set( selectedRoleTemplates.value = new Set(
JSON.parse( JSON.parse(

View File

@ -61,7 +61,9 @@ const handleDelete = async (role: Role) => {
confirmType: "danger", confirmType: "danger",
onConfirm: async () => { onConfirm: async () => {
try { try {
await apiClient.extension.role.deletev1alpha1Role(role.metadata.name); await apiClient.extension.role.deletev1alpha1Role({
name: role.metadata.name,
});
} catch (e) { } catch (e) {
console.error("Failed to delete role", e); console.error("Failed to delete role", e);
} }

View File

@ -57,9 +57,11 @@ export function useFetchRole(): useFetchRoleReturn {
const handleFetchRoles = async () => { const handleFetchRoles = async () => {
try { try {
loading.value = true; loading.value = true;
const { data } = await apiClient.extension.role.listv1alpha1Role(0, 0, [ const { data } = await apiClient.extension.role.listv1alpha1Role({
`!${roleLabels.TEMPLATE}`, page: 0,
]); size: 0,
labelSelector: [`!${roleLabels.TEMPLATE}`],
});
roles.value = data.items; roles.value = data.items;
} catch (e) { } catch (e) {
console.error("Failed to fetch roles", e); console.error("Failed to fetch roles", e);
@ -94,12 +96,14 @@ export function useRoleForm(): useRoleFormReturn {
try { try {
saving.value = true; saving.value = true;
if (isUpdateMode.value) { if (isUpdateMode.value) {
await apiClient.extension.role.updatev1alpha1Role( await apiClient.extension.role.updatev1alpha1Role({
formState.value.metadata.name, name: formState.value.metadata.name,
formState.value role: formState.value,
); });
} else { } else {
await apiClient.extension.role.createv1alpha1Role(formState.value); await apiClient.extension.role.createv1alpha1Role({
role: formState.value,
});
} }
} catch (e) { } catch (e) {
console.error(e); console.error(e);
@ -233,10 +237,11 @@ export function useRoleTemplateSelection(): useRoleTemplateSelectionReturn {
*/ */
const handleFetchRoles = async () => { const handleFetchRoles = async () => {
try { try {
const { data } = await apiClient.extension.role.listv1alpha1Role(0, 0, [ const { data } = await apiClient.extension.role.listv1alpha1Role({
`${roleLabels.TEMPLATE}=true`, page: 0,
"!halo.run/hidden", size: 0,
]); labelSelector: [`${roleLabels.TEMPLATE}=true`, "!halo.run/hidden"],
});
roleTemplates.value = data.items; roleTemplates.value = data.items;
} catch (e) { } catch (e) {
console.error(e); console.error(e);

View File

@ -38,10 +38,10 @@ const selectedUser = ref<User | null>(null);
const handleFetchUsers = async () => { const handleFetchUsers = async () => {
try { try {
const { data } = await apiClient.extension.user.listv1alpha1User( const { data } = await apiClient.extension.user.listv1alpha1User({
users.value.page, page: users.value.page,
users.value.size size: users.value.size,
); });
users.value = data; users.value = data;
} catch (e) { } catch (e) {
console.error(e); console.error(e);

View File

@ -148,22 +148,24 @@ const handleCreateUser = async () => {
let user: User; let user: User;
if (isUpdateMode.value) { if (isUpdateMode.value) {
const response = await apiClient.extension.user.updatev1alpha1User( const response = await apiClient.extension.user.updatev1alpha1User({
formState.value.user.metadata.name, name: formState.value.user.metadata.name,
formState.value.user user: formState.value.user,
); });
user = response.data; user = response.data;
} else { } else {
const response = await apiClient.extension.user.createv1alpha1User( const response = await apiClient.extension.user.createv1alpha1User({
formState.value.user user: formState.value.user,
); });
user = response.data; user = response.data;
} }
if (selectedRole.value) { if (selectedRole.value) {
await apiClient.user.grantPermission(user.metadata.name, { await apiClient.user.grantPermission({
// @ts-ignore name: user.metadata.name,
roles: [selectedRole.value], grantRequest: {
roles: [selectedRole.value],
},
}); });
} }

View File

@ -56,12 +56,15 @@ const handleChangePassword = async () => {
delete changePasswordRequest.password_confirm; delete changePasswordRequest.password_confirm;
if (props.user?.metadata.name === currentUser?.metadata.name) { if (props.user?.metadata.name === currentUser?.metadata.name) {
await apiClient.user.changePassword("-", changePasswordRequest); await apiClient.user.changePassword({
name: "-",
changePasswordRequest,
});
} else { } else {
await apiClient.user.changePassword( await apiClient.user.changePassword({
props.user?.metadata.name || "", name: props.user?.metadata.name || "",
changePasswordRequest changePasswordRequest,
); });
} }
handleVisibleChange(false); handleVisibleChange(false);

View File

@ -28,9 +28,9 @@ const { params } = useRoute();
const handleFetchUser = async () => { const handleFetchUser = async () => {
try { try {
const { data } = await apiClient.extension.user.getv1alpha1User( const { data } = await apiClient.extension.user.getv1alpha1User({
params.name as string name: params.name as string,
); });
user.value = data; user.value = data;
} catch (e) { } catch (e) {
console.error(e); console.error(e);

View File

@ -11,8 +11,8 @@ export const useRoleStore = defineStore({
state: (): RoleStoreState => ({ state: (): RoleStoreState => ({
roles: [], roles: [],
permissions: { permissions: {
roles: new Set<Role>([]), roles: [],
uiPermissions: new Set<string>([]), uiPermissions: [],
}, },
}), }),
}); });