mirror of https://github.com/halo-dev/halo-admin
refactor: use generateName instead of uuid to generate metadata.name (#688)
#### What type of PR is this? /kind improvement /milestone 2.0 #### What this PR does / why we need it: 使用 metadata.generateName 代替 uuid 为 metadata.name 生成值。 Ref https://github.com/halo-dev/halo/pull/2563 #### Special notes for your reviewer: /cc @halo-dev/sig-halo-console 测试方式: 1. 需要 `pnpm install` 2. 测试登录以及所有需要创建更新资源的业务模块。 #### Does this PR introduce a user-facing change? ```release-note None ```pull/695/head
parent
1b8805a340
commit
616bdc8307
|
@ -64,7 +64,6 @@
|
||||||
"pinia": "^2.0.23",
|
"pinia": "^2.0.23",
|
||||||
"pretty-bytes": "^6.0.0",
|
"pretty-bytes": "^6.0.0",
|
||||||
"qs": "^6.11.0",
|
"qs": "^6.11.0",
|
||||||
"uuid": "^9.0.0",
|
|
||||||
"vue": "^3.2.44",
|
"vue": "^3.2.44",
|
||||||
"vue-grid-layout": "3.0.0-beta1",
|
"vue-grid-layout": "3.0.0-beta1",
|
||||||
"vue-router": "^4.1.6",
|
"vue-router": "^4.1.6",
|
||||||
|
@ -84,7 +83,6 @@
|
||||||
"@types/node": "^18.11.9",
|
"@types/node": "^18.11.9",
|
||||||
"@types/qs": "^6.9.7",
|
"@types/qs": "^6.9.7",
|
||||||
"@types/randomstring": "^1.1.8",
|
"@types/randomstring": "^1.1.8",
|
||||||
"@types/uuid": "^8.3.4",
|
|
||||||
"@vitejs/plugin-vue": "^3.2.0",
|
"@vitejs/plugin-vue": "^3.2.0",
|
||||||
"@vitejs/plugin-vue-jsx": "^2.1.1",
|
"@vitejs/plugin-vue-jsx": "^2.1.1",
|
||||||
"@vitest/ui": "^0.25.1",
|
"@vitest/ui": "^0.25.1",
|
||||||
|
|
|
@ -28,7 +28,6 @@ importers:
|
||||||
'@types/node': ^18.11.9
|
'@types/node': ^18.11.9
|
||||||
'@types/qs': ^6.9.7
|
'@types/qs': ^6.9.7
|
||||||
'@types/randomstring': ^1.1.8
|
'@types/randomstring': ^1.1.8
|
||||||
'@types/uuid': ^8.3.4
|
|
||||||
'@uppy/core': ^3.0.4
|
'@uppy/core': ^3.0.4
|
||||||
'@uppy/dashboard': ^3.2.0
|
'@uppy/dashboard': ^3.2.0
|
||||||
'@uppy/drag-drop': ^3.0.1
|
'@uppy/drag-drop': ^3.0.1
|
||||||
|
@ -83,7 +82,6 @@ importers:
|
||||||
tailwindcss-themer: ^2.0.2
|
tailwindcss-themer: ^2.0.2
|
||||||
typescript: ~4.7.4
|
typescript: ~4.7.4
|
||||||
unplugin-icons: ^0.14.13
|
unplugin-icons: ^0.14.13
|
||||||
uuid: ^9.0.0
|
|
||||||
vite: ^3.2.3
|
vite: ^3.2.3
|
||||||
vite-compression-plugin: ^0.0.4
|
vite-compression-plugin: ^0.0.4
|
||||||
vite-plugin-externals: ^0.5.1
|
vite-plugin-externals: ^0.5.1
|
||||||
|
@ -138,7 +136,6 @@ importers:
|
||||||
pinia: 2.0.23_e7lp6ggkpgyi5vqd44m2kxvk6i
|
pinia: 2.0.23_e7lp6ggkpgyi5vqd44m2kxvk6i
|
||||||
pretty-bytes: 6.0.0
|
pretty-bytes: 6.0.0
|
||||||
qs: 6.11.0
|
qs: 6.11.0
|
||||||
uuid: 9.0.0
|
|
||||||
vue: 3.2.45
|
vue: 3.2.45
|
||||||
vue-grid-layout: 3.0.0-beta1
|
vue-grid-layout: 3.0.0-beta1
|
||||||
vue-router: 4.1.6_vue@3.2.45
|
vue-router: 4.1.6_vue@3.2.45
|
||||||
|
@ -157,7 +154,6 @@ importers:
|
||||||
'@types/node': 18.11.9
|
'@types/node': 18.11.9
|
||||||
'@types/qs': 6.9.7
|
'@types/qs': 6.9.7
|
||||||
'@types/randomstring': 1.1.8
|
'@types/randomstring': 1.1.8
|
||||||
'@types/uuid': 8.3.4
|
|
||||||
'@vitejs/plugin-vue': 3.2.0_vite@3.2.4+vue@3.2.45
|
'@vitejs/plugin-vue': 3.2.0_vite@3.2.4+vue@3.2.45
|
||||||
'@vitejs/plugin-vue-jsx': 2.1.1_vite@3.2.4+vue@3.2.45
|
'@vitejs/plugin-vue-jsx': 2.1.1_vite@3.2.4+vue@3.2.45
|
||||||
'@vitest/ui': 0.25.2
|
'@vitest/ui': 0.25.2
|
||||||
|
@ -3229,10 +3225,6 @@ packages:
|
||||||
resolution: {integrity: sha512-PBjIUxZHOuj0R15/xuwJYjFi+KZdNFrehocChv4g5hu6aFroHue8m0lBP0POdK2nKzbw0cgV1mws8+V/JAcEkQ==}
|
resolution: {integrity: sha512-PBjIUxZHOuj0R15/xuwJYjFi+KZdNFrehocChv4g5hu6aFroHue8m0lBP0POdK2nKzbw0cgV1mws8+V/JAcEkQ==}
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/@types/uuid/8.3.4:
|
|
||||||
resolution: {integrity: sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw==}
|
|
||||||
dev: true
|
|
||||||
|
|
||||||
/@types/web-bluetooth/0.0.16:
|
/@types/web-bluetooth/0.0.16:
|
||||||
resolution: {integrity: sha512-oh8q2Zc32S6gd/j50GowEjKLoOVOwHP/bWVjKJInBwQqdOYMdPrf1oVlelTlyfFK3CKxL1uahMDAr+vy8T7yMQ==}
|
resolution: {integrity: sha512-oh8q2Zc32S6gd/j50GowEjKLoOVOwHP/bWVjKJInBwQqdOYMdPrf1oVlelTlyfFK3CKxL1uahMDAr+vy8T7yMQ==}
|
||||||
dev: false
|
dev: false
|
||||||
|
@ -9043,11 +9035,6 @@ packages:
|
||||||
hasBin: true
|
hasBin: true
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/uuid/9.0.0:
|
|
||||||
resolution: {integrity: sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==}
|
|
||||||
hasBin: true
|
|
||||||
dev: false
|
|
||||||
|
|
||||||
/v8-to-istanbul/9.0.1:
|
/v8-to-istanbul/9.0.1:
|
||||||
resolution: {integrity: sha512-74Y4LqY74kLE6IFyIjPtkSTWzUZmj8tdHT9Ii/26dvQ6K9Dl2NbEfj0XgU2sHCtKgt5VupqhlO/5aWuqS+IY1w==}
|
resolution: {integrity: sha512-74Y4LqY74kLE6IFyIjPtkSTWzUZmj8tdHT9Ii/26dvQ6K9Dl2NbEfj0XgU2sHCtKgt5VupqhlO/5aWuqS+IY1w==}
|
||||||
engines: {node: '>=10.12.0'}
|
engines: {node: '>=10.12.0'}
|
||||||
|
|
|
@ -133,14 +133,19 @@ export function useSettingForm(
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!configMap.value.metadata.creationTimestamp) {
|
if (!configMap.value.metadata.creationTimestamp) {
|
||||||
await apiClient.extension.configMap.createv1alpha1ConfigMap({
|
const { data } =
|
||||||
configMap: configMap.value,
|
await apiClient.extension.configMap.createv1alpha1ConfigMap({
|
||||||
});
|
configMap: configMap.value,
|
||||||
|
});
|
||||||
|
|
||||||
|
configMapName.value = data.metadata.name;
|
||||||
} else {
|
} else {
|
||||||
await apiClient.extension.configMap.updatev1alpha1ConfigMap({
|
const { data } =
|
||||||
configMap: configMap.value,
|
await apiClient.extension.configMap.updatev1alpha1ConfigMap({
|
||||||
name: configMap.value.metadata.name,
|
configMap: configMap.value,
|
||||||
});
|
name: configMap.value.metadata.name,
|
||||||
|
});
|
||||||
|
configMapName.value = data.metadata.name;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Failed to save configMap", e);
|
console.error("Failed to save configMap", e);
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
import { VButton, VModal, VSpace } from "@halo-dev/components";
|
import { VButton, VModal, VSpace } from "@halo-dev/components";
|
||||||
import SubmitButton from "@/components/button/SubmitButton.vue";
|
import SubmitButton from "@/components/button/SubmitButton.vue";
|
||||||
import type { Group } from "@halo-dev/api-client";
|
import type { Group } from "@halo-dev/api-client";
|
||||||
import { v4 as uuid } from "uuid";
|
|
||||||
import { computed, ref, watch } from "vue";
|
import { computed, ref, watch } from "vue";
|
||||||
import cloneDeep from "lodash.clonedeep";
|
import cloneDeep from "lodash.clonedeep";
|
||||||
import { apiClient } from "@/utils/api-client";
|
import { apiClient } from "@/utils/api-client";
|
||||||
|
@ -32,7 +31,8 @@ const initialFormState: Group = {
|
||||||
apiVersion: "storage.halo.run/v1alpha1",
|
apiVersion: "storage.halo.run/v1alpha1",
|
||||||
kind: "Group",
|
kind: "Group",
|
||||||
metadata: {
|
metadata: {
|
||||||
name: uuid(),
|
name: "",
|
||||||
|
generateName: "attachment-group-",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -81,7 +81,6 @@ const onVisibleChange = (visible: boolean) => {
|
||||||
|
|
||||||
const handleResetForm = () => {
|
const handleResetForm = () => {
|
||||||
formState.value = cloneDeep(initialFormState);
|
formState.value = cloneDeep(initialFormState);
|
||||||
formState.value.metadata.name = uuid();
|
|
||||||
reset("attachment-group-form");
|
reset("attachment-group-form");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,6 @@ import {
|
||||||
import AttachmentPolicyEditingModal from "./AttachmentPolicyEditingModal.vue";
|
import AttachmentPolicyEditingModal from "./AttachmentPolicyEditingModal.vue";
|
||||||
import { ref, watch } from "vue";
|
import { ref, watch } from "vue";
|
||||||
import type { Policy, PolicyTemplate } from "@halo-dev/api-client";
|
import type { Policy, PolicyTemplate } from "@halo-dev/api-client";
|
||||||
import { v4 as uuid } from "uuid";
|
|
||||||
import { formatDatetime } from "@/utils/date";
|
import { formatDatetime } from "@/utils/date";
|
||||||
import {
|
import {
|
||||||
useFetchAttachmentPolicy,
|
useFetchAttachmentPolicy,
|
||||||
|
@ -61,13 +60,14 @@ const handleOpenCreateNewPolicyModal = (policyTemplate: PolicyTemplate) => {
|
||||||
name: policyTemplate.metadata.name,
|
name: policyTemplate.metadata.name,
|
||||||
},
|
},
|
||||||
configMapRef: {
|
configMapRef: {
|
||||||
name: uuid(),
|
name: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
apiVersion: "storage.halo.run/v1alpha1",
|
apiVersion: "storage.halo.run/v1alpha1",
|
||||||
kind: "Policy",
|
kind: "Policy",
|
||||||
metadata: {
|
metadata: {
|
||||||
name: uuid(),
|
name: "",
|
||||||
|
generateName: "attachment-policy-",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
policyEditingModal.value = true;
|
policyEditingModal.value = true;
|
||||||
|
@ -221,6 +221,7 @@ watch(
|
||||||
</VModal>
|
</VModal>
|
||||||
|
|
||||||
<AttachmentPolicyEditingModal
|
<AttachmentPolicyEditingModal
|
||||||
|
v-if="visible"
|
||||||
v-model:visible="policyEditingModal"
|
v-model:visible="policyEditingModal"
|
||||||
:policy="selectedPolicy"
|
:policy="selectedPolicy"
|
||||||
@close="onEditingModalClose"
|
@close="onEditingModalClose"
|
||||||
|
|
|
@ -6,7 +6,6 @@ import cloneDeep from "lodash.clonedeep";
|
||||||
import { computed, ref, watch, watchEffect } from "vue";
|
import { computed, ref, watch, watchEffect } from "vue";
|
||||||
import { useSettingForm } from "@/composables/use-setting-form";
|
import { useSettingForm } from "@/composables/use-setting-form";
|
||||||
import { apiClient } from "@/utils/api-client";
|
import { apiClient } from "@/utils/api-client";
|
||||||
import { v4 as uuid } from "uuid";
|
|
||||||
import {
|
import {
|
||||||
reset,
|
reset,
|
||||||
type FormKitSchemaCondition,
|
type FormKitSchemaCondition,
|
||||||
|
@ -43,7 +42,8 @@ const initialFormState: Policy = {
|
||||||
apiVersion: "storage.halo.run/v1alpha1",
|
apiVersion: "storage.halo.run/v1alpha1",
|
||||||
kind: "Policy",
|
kind: "Policy",
|
||||||
metadata: {
|
metadata: {
|
||||||
name: uuid(),
|
name: "",
|
||||||
|
generateName: "attachment-policy-",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -53,11 +53,22 @@ const policyTemplate = ref<PolicyTemplate | undefined>();
|
||||||
const settingName = computed(
|
const settingName = computed(
|
||||||
() => policyTemplate.value?.spec?.settingRef?.name
|
() => policyTemplate.value?.spec?.settingRef?.name
|
||||||
);
|
);
|
||||||
const configMapName = computed(() => formState.value.spec.configMapRef?.name);
|
|
||||||
|
const configMapName = computed({
|
||||||
|
get() {
|
||||||
|
return formState.value.spec.configMapRef?.name;
|
||||||
|
},
|
||||||
|
set(value) {
|
||||||
|
formState.value.spec.configMapRef = {
|
||||||
|
name: value as string,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const {
|
const {
|
||||||
setting,
|
setting,
|
||||||
configMapFormData,
|
configMapFormData,
|
||||||
|
configMap,
|
||||||
saving,
|
saving,
|
||||||
handleFetchConfigMap,
|
handleFetchConfigMap,
|
||||||
handleFetchSettings,
|
handleFetchSettings,
|
||||||
|
@ -102,6 +113,11 @@ const handleSave = async () => {
|
||||||
try {
|
try {
|
||||||
saving.value = true;
|
saving.value = true;
|
||||||
|
|
||||||
|
if (!isUpdateMode.value) {
|
||||||
|
configMap.value.metadata.name = "";
|
||||||
|
configMap.value.metadata.generateName = "configMap-";
|
||||||
|
}
|
||||||
|
|
||||||
await handleSaveConfigMap();
|
await handleSaveConfigMap();
|
||||||
|
|
||||||
if (isUpdateMode.value) {
|
if (isUpdateMode.value) {
|
||||||
|
@ -112,6 +128,9 @@ const handleSave = async () => {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
formState.value.spec.configMapRef = {
|
||||||
|
name: configMap.value.metadata.name,
|
||||||
|
};
|
||||||
await apiClient.extension.storage.policy.createstorageHaloRunV1alpha1Policy(
|
await apiClient.extension.storage.policy.createstorageHaloRunV1alpha1Policy(
|
||||||
{
|
{
|
||||||
policy: formState.value,
|
policy: formState.value,
|
||||||
|
@ -129,7 +148,6 @@ const handleSave = async () => {
|
||||||
|
|
||||||
const handleResetForm = () => {
|
const handleResetForm = () => {
|
||||||
formState.value = cloneDeep(initialFormState);
|
formState.value = cloneDeep(initialFormState);
|
||||||
formState.value.metadata.name = uuid();
|
|
||||||
reset("attachment-policy-form");
|
reset("attachment-policy-form");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@ import {
|
||||||
useFetchAttachmentPolicyTemplate,
|
useFetchAttachmentPolicyTemplate,
|
||||||
} from "../composables/use-attachment-policy";
|
} from "../composables/use-attachment-policy";
|
||||||
import AttachmentPolicyEditingModal from "./AttachmentPolicyEditingModal.vue";
|
import AttachmentPolicyEditingModal from "./AttachmentPolicyEditingModal.vue";
|
||||||
import { v4 as uuid } from "uuid";
|
|
||||||
|
|
||||||
const props = withDefaults(
|
const props = withDefaults(
|
||||||
defineProps<{
|
defineProps<{
|
||||||
|
@ -33,6 +32,7 @@ const { policyTemplates, handleFetchPolicyTemplates } =
|
||||||
useFetchAttachmentPolicyTemplate();
|
useFetchAttachmentPolicyTemplate();
|
||||||
|
|
||||||
const selectedPolicy = ref<Policy>();
|
const selectedPolicy = ref<Policy>();
|
||||||
|
const policyToCreate = ref<Policy>();
|
||||||
const uploadVisible = ref(false);
|
const uploadVisible = ref(false);
|
||||||
const policyEditingModal = ref(false);
|
const policyEditingModal = ref(false);
|
||||||
|
|
||||||
|
@ -50,20 +50,21 @@ watchEffect(() => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleOpenCreateNewPolicyModal = (policyTemplate: PolicyTemplate) => {
|
const handleOpenCreateNewPolicyModal = (policyTemplate: PolicyTemplate) => {
|
||||||
selectedPolicy.value = {
|
policyToCreate.value = {
|
||||||
spec: {
|
spec: {
|
||||||
displayName: "",
|
displayName: "",
|
||||||
templateRef: {
|
templateRef: {
|
||||||
name: policyTemplate.metadata.name,
|
name: policyTemplate.metadata.name,
|
||||||
},
|
},
|
||||||
configMapRef: {
|
configMapRef: {
|
||||||
name: uuid(),
|
name: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
apiVersion: "storage.halo.run/v1alpha1",
|
apiVersion: "storage.halo.run/v1alpha1",
|
||||||
kind: "Policy",
|
kind: "Policy",
|
||||||
metadata: {
|
metadata: {
|
||||||
name: uuid(),
|
name: "",
|
||||||
|
generateName: "attachment-policy-",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
policyEditingModal.value = true;
|
policyEditingModal.value = true;
|
||||||
|
@ -71,7 +72,7 @@ const handleOpenCreateNewPolicyModal = (policyTemplate: PolicyTemplate) => {
|
||||||
|
|
||||||
const onEditingModalClose = async () => {
|
const onEditingModalClose = async () => {
|
||||||
await handleFetchPolicies();
|
await handleFetchPolicies();
|
||||||
selectedPolicy.value = policies.value[0];
|
policyToCreate.value = policies.value[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
const onVisibleChange = (visible: boolean) => {
|
const onVisibleChange = (visible: boolean) => {
|
||||||
|
@ -181,8 +182,9 @@ watch(
|
||||||
</VModal>
|
</VModal>
|
||||||
|
|
||||||
<AttachmentPolicyEditingModal
|
<AttachmentPolicyEditingModal
|
||||||
|
v-if="visible"
|
||||||
v-model:visible="policyEditingModal"
|
v-model:visible="policyEditingModal"
|
||||||
:policy="selectedPolicy"
|
:policy="policyToCreate"
|
||||||
@close="onEditingModalClose"
|
@close="onEditingModalClose"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -12,12 +12,12 @@ import DefaultEditor from "@/components/editor/DefaultEditor.vue";
|
||||||
import SinglePageSettingModal from "./components/SinglePageSettingModal.vue";
|
import SinglePageSettingModal from "./components/SinglePageSettingModal.vue";
|
||||||
import PostPreviewModal from "../posts/components/PostPreviewModal.vue";
|
import PostPreviewModal from "../posts/components/PostPreviewModal.vue";
|
||||||
import type { SinglePage, SinglePageRequest } from "@halo-dev/api-client";
|
import type { SinglePage, SinglePageRequest } from "@halo-dev/api-client";
|
||||||
import { v4 as uuid } from "uuid";
|
|
||||||
import { computed, onMounted, ref } from "vue";
|
import { computed, onMounted, ref } from "vue";
|
||||||
import { apiClient } from "@/utils/api-client";
|
import { apiClient } from "@/utils/api-client";
|
||||||
import { useRouteQuery } from "@vueuse/router";
|
import { useRouteQuery } from "@vueuse/router";
|
||||||
import cloneDeep from "lodash.clonedeep";
|
import cloneDeep from "lodash.clonedeep";
|
||||||
import { useRouter } from "vue-router";
|
import { useRouter } from "vue-router";
|
||||||
|
import { randomUUID } from "@/utils/id";
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ const initialFormState: SinglePageRequest = {
|
||||||
apiVersion: "content.halo.run/v1alpha1",
|
apiVersion: "content.halo.run/v1alpha1",
|
||||||
kind: "SinglePage",
|
kind: "SinglePage",
|
||||||
metadata: {
|
metadata: {
|
||||||
name: uuid(),
|
name: randomUUID(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
content: {
|
content: {
|
||||||
|
@ -79,7 +79,7 @@ const handleSave = async () => {
|
||||||
formState.value.page.spec.title = "无标题页面";
|
formState.value.page.spec.title = "无标题页面";
|
||||||
}
|
}
|
||||||
if (!formState.value.page.spec.slug) {
|
if (!formState.value.page.spec.slug) {
|
||||||
formState.value.page.spec.slug = uuid();
|
formState.value.page.spec.slug = new Date().getTime().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isUpdateMode.value) {
|
if (isUpdateMode.value) {
|
||||||
|
|
|
@ -4,9 +4,9 @@ import { computed, ref, watchEffect } from "vue";
|
||||||
import type { SinglePage } from "@halo-dev/api-client";
|
import type { SinglePage } from "@halo-dev/api-client";
|
||||||
import cloneDeep from "lodash.clonedeep";
|
import cloneDeep from "lodash.clonedeep";
|
||||||
import { apiClient } from "@/utils/api-client";
|
import { apiClient } from "@/utils/api-client";
|
||||||
import { v4 as uuid } from "uuid";
|
|
||||||
import { useThemeCustomTemplates } from "@/modules/interface/themes/composables/use-theme";
|
import { useThemeCustomTemplates } from "@/modules/interface/themes/composables/use-theme";
|
||||||
import { singlePageLabels } from "@/constants/labels";
|
import { singlePageLabels } from "@/constants/labels";
|
||||||
|
import { randomUUID } from "@/utils/id";
|
||||||
|
|
||||||
const initialFormState: SinglePage = {
|
const initialFormState: SinglePage = {
|
||||||
spec: {
|
spec: {
|
||||||
|
@ -31,7 +31,7 @@ const initialFormState: SinglePage = {
|
||||||
apiVersion: "content.halo.run/v1alpha1",
|
apiVersion: "content.halo.run/v1alpha1",
|
||||||
kind: "SinglePage",
|
kind: "SinglePage",
|
||||||
metadata: {
|
metadata: {
|
||||||
name: uuid(),
|
name: randomUUID(),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,8 @@ import { computed, onMounted, ref } from "vue";
|
||||||
import cloneDeep from "lodash.clonedeep";
|
import cloneDeep from "lodash.clonedeep";
|
||||||
import { apiClient } from "@/utils/api-client";
|
import { apiClient } from "@/utils/api-client";
|
||||||
import { useRouteQuery } from "@vueuse/router";
|
import { useRouteQuery } from "@vueuse/router";
|
||||||
import { v4 as uuid } from "uuid";
|
|
||||||
import { useRouter } from "vue-router";
|
import { useRouter } from "vue-router";
|
||||||
|
import { randomUUID } from "@/utils/id";
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ const initialFormState: PostRequest = {
|
||||||
apiVersion: "content.halo.run/v1alpha1",
|
apiVersion: "content.halo.run/v1alpha1",
|
||||||
kind: "Post",
|
kind: "Post",
|
||||||
metadata: {
|
metadata: {
|
||||||
name: uuid(),
|
name: randomUUID(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
content: {
|
content: {
|
||||||
|
@ -80,7 +80,7 @@ const handleSave = async () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!formState.value.post.spec.slug) {
|
if (!formState.value.post.spec.slug) {
|
||||||
formState.value.post.spec.slug = uuid();
|
formState.value.post.spec.slug = new Date().getTime().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isUpdateMode.value) {
|
if (isUpdateMode.value) {
|
||||||
|
|
|
@ -14,7 +14,6 @@ import type { Category } from "@halo-dev/api-client";
|
||||||
import cloneDeep from "lodash.clonedeep";
|
import cloneDeep from "lodash.clonedeep";
|
||||||
import { reset } from "@formkit/core";
|
import { reset } from "@formkit/core";
|
||||||
import { setFocus } from "@/formkit/utils/focus";
|
import { setFocus } from "@/formkit/utils/focus";
|
||||||
import { v4 as uuid } from "uuid";
|
|
||||||
import { useThemeCustomTemplates } from "@/modules/interface/themes/composables/use-theme";
|
import { useThemeCustomTemplates } from "@/modules/interface/themes/composables/use-theme";
|
||||||
|
|
||||||
const props = withDefaults(
|
const props = withDefaults(
|
||||||
|
@ -47,7 +46,8 @@ const initialFormState: Category = {
|
||||||
apiVersion: "content.halo.run/v1alpha1",
|
apiVersion: "content.halo.run/v1alpha1",
|
||||||
kind: "Category",
|
kind: "Category",
|
||||||
metadata: {
|
metadata: {
|
||||||
name: uuid(),
|
name: "",
|
||||||
|
generateName: "category-",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -92,7 +92,6 @@ const onVisibleChange = (visible: boolean) => {
|
||||||
|
|
||||||
const handleResetForm = () => {
|
const handleResetForm = () => {
|
||||||
formState.value = cloneDeep(initialFormState);
|
formState.value = cloneDeep(initialFormState);
|
||||||
formState.value.metadata.name = uuid();
|
|
||||||
reset("category-form");
|
reset("category-form");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,9 @@ import { computed, ref, watchEffect } from "vue";
|
||||||
import type { Post } from "@halo-dev/api-client";
|
import type { Post } from "@halo-dev/api-client";
|
||||||
import cloneDeep from "lodash.clonedeep";
|
import cloneDeep from "lodash.clonedeep";
|
||||||
import { apiClient } from "@/utils/api-client";
|
import { apiClient } from "@/utils/api-client";
|
||||||
import { v4 as uuid } from "uuid";
|
|
||||||
import { useThemeCustomTemplates } from "@/modules/interface/themes/composables/use-theme";
|
import { useThemeCustomTemplates } from "@/modules/interface/themes/composables/use-theme";
|
||||||
import { postLabels } from "@/constants/labels";
|
import { postLabels } from "@/constants/labels";
|
||||||
|
import { randomUUID } from "@/utils/id";
|
||||||
|
|
||||||
const initialFormState: Post = {
|
const initialFormState: Post = {
|
||||||
spec: {
|
spec: {
|
||||||
|
@ -33,7 +33,7 @@ const initialFormState: Post = {
|
||||||
apiVersion: "content.halo.run/v1alpha1",
|
apiVersion: "content.halo.run/v1alpha1",
|
||||||
kind: "Post",
|
kind: "Post",
|
||||||
metadata: {
|
metadata: {
|
||||||
name: uuid(),
|
name: randomUUID(),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@ import type { Tag } from "@halo-dev/api-client";
|
||||||
import cloneDeep from "lodash.clonedeep";
|
import cloneDeep from "lodash.clonedeep";
|
||||||
import { reset } from "@formkit/core";
|
import { reset } from "@formkit/core";
|
||||||
import { setFocus } from "@/formkit/utils/focus";
|
import { setFocus } from "@/formkit/utils/focus";
|
||||||
import { v4 as uuid } from "uuid";
|
|
||||||
|
|
||||||
const props = withDefaults(
|
const props = withDefaults(
|
||||||
defineProps<{
|
defineProps<{
|
||||||
|
@ -50,7 +49,8 @@ const initialFormState: Tag = {
|
||||||
apiVersion: "content.halo.run/v1alpha1",
|
apiVersion: "content.halo.run/v1alpha1",
|
||||||
kind: "Tag",
|
kind: "Tag",
|
||||||
metadata: {
|
metadata: {
|
||||||
name: uuid(),
|
name: "",
|
||||||
|
generateName: "tag-",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -95,7 +95,6 @@ const onVisibleChange = (visible: boolean) => {
|
||||||
|
|
||||||
const handleResetForm = () => {
|
const handleResetForm = () => {
|
||||||
formState.value = cloneDeep(initialFormState);
|
formState.value = cloneDeep(initialFormState);
|
||||||
formState.value.metadata.name = uuid();
|
|
||||||
reset("tag-form");
|
reset("tag-form");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
import { VButton, VModal, VSpace } from "@halo-dev/components";
|
import { VButton, VModal, VSpace } from "@halo-dev/components";
|
||||||
import SubmitButton from "@/components/button/SubmitButton.vue";
|
import SubmitButton from "@/components/button/SubmitButton.vue";
|
||||||
import type { Menu } from "@halo-dev/api-client";
|
import type { Menu } from "@halo-dev/api-client";
|
||||||
import { v4 as uuid } from "uuid";
|
|
||||||
import { computed, ref, watch } from "vue";
|
import { computed, ref, watch } from "vue";
|
||||||
import { apiClient } from "@/utils/api-client";
|
import { apiClient } from "@/utils/api-client";
|
||||||
import { reset } from "@formkit/core";
|
import { reset } from "@formkit/core";
|
||||||
|
@ -34,7 +33,8 @@ const initialFormState: Menu = {
|
||||||
apiVersion: "v1alpha1",
|
apiVersion: "v1alpha1",
|
||||||
kind: "Menu",
|
kind: "Menu",
|
||||||
metadata: {
|
metadata: {
|
||||||
name: uuid(),
|
name: "",
|
||||||
|
generateName: "menu-",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -76,7 +76,6 @@ const onVisibleChange = (visible: boolean) => {
|
||||||
|
|
||||||
const handleResetForm = () => {
|
const handleResetForm = () => {
|
||||||
formState.value = cloneDeep(initialFormState);
|
formState.value = cloneDeep(initialFormState);
|
||||||
formState.value.metadata.name = uuid();
|
|
||||||
reset("menu-form");
|
reset("menu-form");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@ import { VButton, VModal, VSpace } from "@halo-dev/components";
|
||||||
import SubmitButton from "@/components/button/SubmitButton.vue";
|
import SubmitButton from "@/components/button/SubmitButton.vue";
|
||||||
import { computed, ref, watch } from "vue";
|
import { computed, ref, watch } from "vue";
|
||||||
import type { Menu, MenuItem } from "@halo-dev/api-client";
|
import type { Menu, MenuItem } from "@halo-dev/api-client";
|
||||||
import { v4 as uuid } from "uuid";
|
|
||||||
import { apiClient } from "@/utils/api-client";
|
import { apiClient } from "@/utils/api-client";
|
||||||
import { reset } from "@formkit/core";
|
import { reset } from "@formkit/core";
|
||||||
import cloneDeep from "lodash.clonedeep";
|
import cloneDeep from "lodash.clonedeep";
|
||||||
|
@ -40,7 +39,8 @@ const initialFormState: MenuItem = {
|
||||||
apiVersion: "v1alpha1",
|
apiVersion: "v1alpha1",
|
||||||
kind: "MenuItem",
|
kind: "MenuItem",
|
||||||
metadata: {
|
metadata: {
|
||||||
name: uuid(),
|
name: "",
|
||||||
|
generateName: "menu-item-",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -122,7 +122,6 @@ const onVisibleChange = (visible: boolean) => {
|
||||||
|
|
||||||
const handleResetForm = () => {
|
const handleResetForm = () => {
|
||||||
formState.value = cloneDeep(initialFormState);
|
formState.value = cloneDeep(initialFormState);
|
||||||
formState.value.metadata.name = uuid();
|
|
||||||
selectedMenuItemSource.value = menuItemSources[0].value;
|
selectedMenuItemSource.value = menuItemSources[0].value;
|
||||||
selectedRef.value = "";
|
selectedRef.value = "";
|
||||||
selectedParentMenuItem.value = "";
|
selectedParentMenuItem.value = "";
|
||||||
|
|
|
@ -10,7 +10,6 @@ import {
|
||||||
} from "@/modules/system/roles/composables/use-role";
|
} from "@/modules/system/roles/composables/use-role";
|
||||||
import cloneDeep from "lodash.clonedeep";
|
import cloneDeep from "lodash.clonedeep";
|
||||||
import { reset } from "@formkit/core";
|
import { reset } from "@formkit/core";
|
||||||
import { v4 as uuid } from "uuid";
|
|
||||||
import { setFocus } from "@/formkit/utils/focus";
|
import { setFocus } from "@/formkit/utils/focus";
|
||||||
|
|
||||||
const props = withDefaults(
|
const props = withDefaults(
|
||||||
|
@ -101,7 +100,6 @@ const onVisibleChange = (visible: boolean) => {
|
||||||
|
|
||||||
const handleResetForm = () => {
|
const handleResetForm = () => {
|
||||||
formState.value = cloneDeep(initialFormState);
|
formState.value = cloneDeep(initialFormState);
|
||||||
formState.value.metadata.name = uuid();
|
|
||||||
reset("role-form");
|
reset("role-form");
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
@ -132,15 +130,6 @@ const handleResetForm = () => {
|
||||||
type="text"
|
type="text"
|
||||||
validation="required"
|
validation="required"
|
||||||
></FormKit>
|
></FormKit>
|
||||||
<FormKit
|
|
||||||
v-model="formState.metadata.name"
|
|
||||||
help="角色别名,用于区分角色,不能重复,创建之后不能修改"
|
|
||||||
label="别名"
|
|
||||||
type="text"
|
|
||||||
name="name"
|
|
||||||
:disabled="isUpdateMode"
|
|
||||||
validation="required"
|
|
||||||
></FormKit>
|
|
||||||
</FormKit>
|
</FormKit>
|
||||||
</VTabItem>
|
</VTabItem>
|
||||||
<VTabItem id="permissions" label="权限">
|
<VTabItem id="permissions" label="权限">
|
||||||
|
|
|
@ -15,6 +15,7 @@ const initialFormState: Role = {
|
||||||
kind: "Role",
|
kind: "Role",
|
||||||
metadata: {
|
metadata: {
|
||||||
name: "",
|
name: "",
|
||||||
|
generateName: "role-",
|
||||||
labels: {},
|
labels: {},
|
||||||
annotations: {
|
annotations: {
|
||||||
[rbacAnnotations.DEPENDENCIES]: "",
|
[rbacAnnotations.DEPENDENCIES]: "",
|
||||||
|
|
|
@ -5,7 +5,6 @@ import {
|
||||||
VButton,
|
VButton,
|
||||||
Toast,
|
Toast,
|
||||||
} from "@halo-dev/components";
|
} from "@halo-dev/components";
|
||||||
import { v4 as uuid } from "uuid";
|
|
||||||
import qs from "qs";
|
import qs from "qs";
|
||||||
import { inject, onBeforeMount, onMounted, ref } from "vue";
|
import { inject, onBeforeMount, onMounted, ref } from "vue";
|
||||||
import { submitForm } from "@formkit/vue";
|
import { submitForm } from "@formkit/vue";
|
||||||
|
@ -14,6 +13,7 @@ import axios from "axios";
|
||||||
import type { User } from "@halo-dev/api-client";
|
import type { User } from "@halo-dev/api-client";
|
||||||
import { setFocus } from "@/formkit/utils/focus";
|
import { setFocus } from "@/formkit/utils/focus";
|
||||||
import IconLogo from "~icons/core/logo?width=5rem&height=2rem";
|
import IconLogo from "~icons/core/logo?width=5rem&height=2rem";
|
||||||
|
import { randomUUID } from "@/utils/id";
|
||||||
|
|
||||||
interface LoginForm {
|
interface LoginForm {
|
||||||
_csrf: string;
|
_csrf: string;
|
||||||
|
@ -30,7 +30,7 @@ const loginForm = ref<LoginForm>({
|
||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
|
|
||||||
const handleGenerateToken = async () => {
|
const handleGenerateToken = async () => {
|
||||||
const token = uuid();
|
const token = randomUUID();
|
||||||
loginForm.value._csrf = token;
|
loginForm.value._csrf = token;
|
||||||
document.cookie = `XSRF-TOKEN=${token}; Path=/;`;
|
document.cookie = `XSRF-TOKEN=${token}; Path=/;`;
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
export function randomUUID() {
|
||||||
|
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
|
||||||
|
const r = (Math.random() * 16) | 0,
|
||||||
|
v = c === "x" ? r : (r & 0x3) | 0x8;
|
||||||
|
return v.toString(16);
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in New Issue