Skip to content

BillionMail gives you open-source MailServer, NewsLetter, Email Marketing — fully self-hosted, dev-friendly, and free from monthly fees. Join the discord: https://discord.gg/asfXzBUhZr

refactor: optimize user template creation logic

albert185b42f7885e
diff --git a/core/frontend/build/utils.ts b/core/frontend/build/utils.ts
index 60967d43..b9422708 100644
--- a/core/frontend/build/utils.ts
+++ b/core/frontend/build/utils.ts
@@ -17,5 +17,6 @@ export function getEnv(key: string) {
*/
export function getServer() {
const name = getEnv('SERVER_NAME') || '192.168.66.124'
+ console.log(`当前服务器: ${name}`)
return serverConfig[name]
}
diff --git a/core/frontend/src/api/modules/domain.ts b/core/frontend/src/api/modules/domain.ts
index 592c9933..bcf9402f 100644
--- a/core/frontend/src/api/modules/domain.ts
+++ b/core/frontend/src/api/modules/domain.ts
@@ -91,7 +91,7 @@ export const setDefaultDomain = (params: { domain: string }) => {
export const initAiConfiguration = (params: { domain: string, urls: string[] }) => {
return instance.post("/askai/project/create", params, {
fetchOptions: {
- loading: 'Setting Default Domain, please wait...',
+ loading: 'Setting domain brand info , please wait...',
successMessage: true,
}
})
diff --git a/core/frontend/src/views/domain/pages/editDomain/components/DomainConfiguration.vue b/core/frontend/src/views/domain/pages/editDomain/components/DomainConfiguration.vue
index 272f64d9..8cc07074 100644
--- a/core/frontend/src/views/domain/pages/editDomain/components/DomainConfiguration.vue
+++ b/core/frontend/src/views/domain/pages/editDomain/components/DomainConfiguration.vue
@@ -16,7 +16,7 @@
<template #label><span class="form-label">{{
$t('domain.edit.domainConfiguration.domain')
}}</span></template>
- <n-input v-model:value="domainTit" @input="syncToUrl"></n-input>
+ <n-input v-model:value="domainTit" @input="syncToUrl" :disabled="true"></n-input>
</n-form-item>
<n-form-item label="">
<template #label><span class="form-label">{{
@@ -68,13 +68,16 @@
</n-card>
<n-card v-else class="mt-5">
- <div class="fw-bold text-4 mb-5 text-[#777]">{{ $t("domain.edit.domainConfiguration.noBrandInfo") }}</div>
+ <div class="fw-bold text-4 mb-5 text-[#777] flex justify-between items-center">
+ <span>{{ $t("domain.edit.domainConfiguration.noBrandInfo") }}</span>
+
+ </div>
<n-alert v-if="!supplierStatus" type="warning" class="mb-15px" :show-icon="false">
<div class="w-100% flex justify-between items-center">
<span class="mr-5">{{
$t('domain.edit.domainConfiguration.aiIntegrationWarning')
}}</span>
- <n-button type="primary" @click="jumpToAiSettings">{{
+ <n-button ghost type="primary" @click="jumpToAiSettings">{{
$t('domain.edit.domainConfiguration.integrateImmediately')
}}</n-button>
</div>
@@ -107,8 +110,16 @@
</n-button> -->
</div>
</n-form-item>
- <n-button type="primary" class="w-100%" @click="createBrandInfo">{{ $t("domain.edit.domainConfiguration.createNow") }}</n-button>
+ <n-button type="primary" @click="createBrandInfo">{{
+ $t("domain.edit.domainConfiguration.createNow")
+ }}</n-button>
</n-card>
+ <n-button type="primary" @click="updateDomain" class="w-100% mt-5">
+ <template #icon>
+ <i class="i-mingcute:save-2-line text-5"></i>
+ </template>
+ {{ $t('domain.edit.save') }}
+ </n-button>
</div>
</div>
@@ -121,7 +132,7 @@ import WaitAndCheckDomainStatus from '@/views/domain/components/WaitAndCheckDoma
import {
checkAiConfiguration,
} from '@/api/modules/domain'
-import { getDomainDetail, syncToUrl, removeUrl, createBrandInfo,switchBrandInfo } from '../controller/domainConfiguration.controller'
+import { getDomainDetail, syncToUrl, removeUrl, createBrandInfo, switchBrandInfo,updateDomain } from '../controller/domainConfiguration.controller'
import { getEditDomainStoreData } from '../store'
const router = useRouter()
const supplierStatus = ref(false)
@@ -150,8 +161,8 @@ const uinitOptions = ref([
value: 'TB',
},
])
-
getDomainDetail(domain)
+
/**
* @description Check AI configuration
*/
@@ -173,7 +184,7 @@ checkAiConfig()
/**
* @description Jump to AI settings page
*/
-function jumpToAiSettings(){
+function jumpToAiSettings() {
router.push({
name: "AiModel"
})
diff --git a/core/frontend/src/views/domain/pages/editDomain/controller/domainConfiguration.controller.ts b/core/frontend/src/views/domain/pages/editDomain/controller/domainConfiguration.controller.ts
index 6d50d337..47648a12 100644
--- a/core/frontend/src/views/domain/pages/editDomain/controller/domainConfiguration.controller.ts
+++ b/core/frontend/src/views/domain/pages/editDomain/controller/domainConfiguration.controller.ts
@@ -1,11 +1,12 @@
import { instance } from '@/api'
import { instanceOptions } from './companyProfile.controller'
import { getEditDomainStoreData } from '../store'
-import { getByteUnit, Message,isUrl } from '@/utils'
+import { getByteUnit, Message, isUrl } from '@/utils'
import { initAiConfiguration } from '@/api/modules/domain'
import { useGlobalStore } from '@/store'
import i18n from '@/i18n'
+
/**
* @description Check if this domain has brand info
*/
@@ -116,9 +117,8 @@ export async function createBrandInfo() {
hasGotDomainConfiguration.value = false
if (urls.value.length == 0 || urls.value[0] == '') {
Message.error(i18n.global.t('domain.edit.domainConfiguration.fillDomain'))
- }else if(!isUrl(urls.value[0])) {
+ } else if (!isUrl(urls.value[0])) {
Message.error(i18n.global.t('domain.edit.domainConfiguration.fillValidDomain'))
-
} else {
try {
await initAiConfiguration({
@@ -126,15 +126,30 @@ export async function createBrandInfo() {
urls: urls.value,
})
globalStore.domainSource = domainTit.value
- waitAndCheckDomainStatusRef.value.open(domainTit.value, () =>
+ waitAndCheckDomainStatusRef.value.open(domainTit.value, () => {
+ updateHasBrandInfo(domainTit.value, 1)
getDomainDetail(domainTit.value)
- )
+ })
} catch (error) {
console.warn(error)
}
}
}
+/**
+ * @description Update field names hasbrandinfo
+ */
+export async function updateHasBrandInfo(domain: string, hasbrandinfo: number) {
+ try {
+ await instance.post('/domains/update', {
+ domain,
+ hasbrandinfo,
+ })
+ } catch (error) {
+ console.warn(error)
+ }
+}
+
/**
* @description Calculate based on units
*/
diff --git a/core/frontend/src/views/domain/pages/editDomain/index.vue b/core/frontend/src/views/domain/pages/editDomain/index.vue
index 082acb24..8da157aa 100644
--- a/core/frontend/src/views/domain/pages/editDomain/index.vue
+++ b/core/frontend/src/views/domain/pages/editDomain/index.vue
@@ -21,7 +21,7 @@
</n-scrollbar>
</div>
- <div v-if="activeTab !== 'Sitemap'" class="footer-tool">
+ <div v-if="!['Domain Configuration','Sitemap'].includes(activeTab)" class="footer-tool">
<n-button type="primary" @click="switchHanldeSave">
<template #icon>
<i class="i-mingcute:save-2-line text-5"></i>
@@ -89,6 +89,7 @@ const contentMap = new Map([
])
const route = useRoute()
+const router = useRouter()
const domain = route.params.domain as string
/**
diff --git a/core/frontend/src/views/template/components/CreateTplModal.vue b/core/frontend/src/views/template/components/CreateTplModal.vue
index be82b88b..8c8079b2 100644
--- a/core/frontend/src/views/template/components/CreateTplModal.vue
+++ b/core/frontend/src/views/template/components/CreateTplModal.vue
@@ -1,33 +1,18 @@
<template>
- <n-modal
- v-model:show="show"
- preset="card"
- draggable
- :close-on-esc="false"
- :mask-closable="false"
- segmented
- class="w-110"
- title="">
+ <n-modal v-model:show="show" preset="card" draggable :close-on-esc="false" :mask-closable="false" segmented
+ class="w-110" title="">
<div class="wrapper">
<div class="creation-methods">
- <div
- v-for="(item, index) in computedMethodsList"
- :key="index"
- :class="['choose-item', { active: choosedMethod == item }]"
- @click="choosedMethod = item">
+ <div v-for="(item, index) in computedMethodsList" :key="index"
+ :class="['choose-item', { active: choosedMethod == item }]" @click="choosedMethod = item">
<span class="item-label">{{ item }}</span>
</div>
</div>
<div :class="['url-source', { hidden: choosedMethod !== 'AI' }]">
<span class="label">{{ $t('template.createTpl.sourceUrl') }}</span>
- <n-select
- v-model:value="sourceDomain"
- class="flex-1"
- label-field="domain"
- value-field="domain"
- :options="domainListHasBrandInfo"
- :disabled="canNotUse"
- :render-label="renderLabel">
+ <n-select v-model:value="sourceDomain" class="flex-1" label-field="domain" value-field="domain"
+ :options="domainListHasBrandInfo" :disabled="canNotUse" :render-label="renderLabel">
+
</n-select>
</div>
<div v-if="noticeShowFlag == 'normal'" class="desc">
@@ -65,17 +50,12 @@
<template #footer>
<div class="flex justify-end">
- <n-button
- type="primary"
- :disabled="
- canNotUse ||
- ['domain-list-empty', 'ai-configuration-invalid', 'invalid-brand-domain'].includes(
- noticeShowFlag
- )
- "
- @click="createTemplate"
- >{{ $t('template.createTpl.create') }}</n-button
- >
+ <n-button type="primary" v-if="choosedMethod == 'AI'" :disabled="canNotUse ||
+ ['domain-list-empty', 'ai-configuration-invalid',].includes(
+ noticeShowFlag
+ )
+ " @click="createTemplate">{{ $t('template.createTpl.create') }}</n-button>
+ <n-button v-else type="primary" @click="createTemplate">{{ $t('template.createTpl.create') }}</n-button>
</div>
</template>
</n-modal>
@@ -85,10 +65,12 @@
import { instance } from '@/api'
import { createAiTemplate } from '../pages/AITemplate/controller'
import { useGlobalStore } from '@/store'
-import { checkAiConfiguration } from '@/api/modules/domain'
+import { checkAiConfiguration, initAiConfiguration } from '@/api/modules/domain'
import aiModelNotice from '@/assets/images/template/model-notice.png'
import brandInfoNotice from '@/assets/images/template/create-brand-info.png'
import { SelectOption } from 'naive-ui'
+import { Message } from '@/utils'
+import { updateHasBrandInfo } from '@/views/domain/pages/editDomain/controller/domainConfiguration.controller'
// import { TemplateStore } from '../pages/AITemplate/dto'
// const store = inject<TemplateStore>('modelStore')!
@@ -100,6 +82,7 @@ const router = useRouter()
const methodsList = ref(['Drag', 'AI', 'HTML'])
const choosedMethod = ref('AI')
const sourceDomain = ref('')
+const currentDomainOption = ref<SelectOption | null>(null)
const show = ref(false)
const emits = defineEmits(['confirmType', 'hasCreateTpl'])
const domainList = ref<any>([])
@@ -176,11 +159,25 @@ function close() {
*/
async function createTemplate() {
if (choosedMethod.value == 'AI') {
+ if (noticeShowFlag.value == "invalid-brand-domain") {
+ const currentDomain = domainList.value.find((item: any) => item.domain === sourceDomain.value)
+ try {
+ await initAiConfiguration({
+ domain: sourceDomain.value,
+ urls: currentDomain.urls,
+ })
+ updateHasBrandInfo(sourceDomain.value, 1)
+ } catch (error) {
+ Message.error('Failed to initialize AI configuration, please try again later.')
+ console.warn(error);
+ }
+ }
const chatId = await createAiTemplate(sourceDomain.value)
if (chatId) {
globalStore.domainSource = sourceDomain.value
router.push({ name: 'ai-template', params: { chatId } })
}
+
} else {
emits('confirmType', choosedMethod.value)
}
@@ -234,6 +231,7 @@ function renderLabel(option: SelectOption) {
}
}
+
defineExpose({
open,
close,
@@ -250,6 +248,7 @@ async function getDomainList() {
},
})) as Record<string, any>
domainList.value = res.list
+ currentDomainOption.value = domainList.value.find((item: SelectOption) => item.domain === sourceDomain.value) || null
if (domainList.value.length == 0) {
globalStore.domainSource = ''
sourceDomain.value = ''