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

feat: Add guidance logic for AI template creation

albert18da9a9ff83d
diff --git a/core/frontend/src/assets/images/template/create-brand-info.png b/core/frontend/src/assets/images/template/create-brand-info.png
new file mode 100644
index 00000000..8a3106f9
Binary files /dev/null and b/core/frontend/src/assets/images/template/create-brand-info.png differ
diff --git a/core/frontend/src/assets/images/template/model-notice.png b/core/frontend/src/assets/images/template/model-notice.png
new file mode 100644
index 00000000..ceb1d58e
Binary files /dev/null and b/core/frontend/src/assets/images/template/model-notice.png differ
diff --git a/core/frontend/src/views/domain/index.vue b/core/frontend/src/views/domain/index.vue
index b3847a46..f9a1682c 100644
--- a/core/frontend/src/views/domain/index.vue
+++ b/core/frontend/src/views/domain/index.vue
@@ -56,6 +56,7 @@ const { tableParams, tableList, loading, tableTotal, getTableData } = useTableDa
})
const router = useRouter()
+const route = useRoute()
// Table columns
const columns = ref<DataTableColumns<MailDomain>>([
@@ -292,6 +293,15 @@ const handleDelete = (row: MailDomain) => {
},
})
}
+
+// Whether should open create modal automic
+const initDomainFlag = ref("")
+onMounted(() => {
+ initDomainFlag.value = route.query.init as string
+ if (initDomainFlag.value === "init-domain") {
+ handleAddDomain()
+ }
+})
</script>
<style lang="scss" scoped>
diff --git a/core/frontend/src/views/template/components/CreateTplModal.vue b/core/frontend/src/views/template/components/CreateTplModal.vue
index 32417233..ba650498 100644
--- a/core/frontend/src/views/template/components/CreateTplModal.vue
+++ b/core/frontend/src/views/template/components/CreateTplModal.vue
@@ -11,27 +11,55 @@
<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">
+ :options="domainListHasBrandInfo" :disabled="canNotUse" :render-label="renderLabel">
</n-select>
</div>
- <div class="desc">
+ <div class="desc" v-if="noticeShowFlag == 'normal'">
{{ $t("template.createTpl.useAiTools") }}
</div>
+ <div v-else-if="noticeShowFlag == 'domain-list-empty'">
+ 请先为BillionMail创建第一个用于发件的域名, <n-button text type="primary" @click="jumpToDomainCreate">立即创建</n-button>
+
+ </div>
+ <div v-else-if="noticeShowFlag == 'ai-configuration-invalid'">
+ 当前并未配置AI大模型,您无法使用AI模型创建邮件模板,
+ <n-popover trigger="hover" placement="right">
+ <template #trigger>
+ <n-button text type="primary" @click="jumpToAiSettings">立即配置</n-button>
+ </template>
+ <n-image :src="aiModelNotice" width="600"></n-image>
+ </n-popover>
+ </div>
+ <div v-else-if="noticeShowFlag == 'invalid-brand-domain'">
+ 请先为域名创建品牌信息,
+ <n-popover trigger="hover" placement="right">
+ <template #trigger>
+ <n-button text type="primary" @click="jumpToDomainEdit">立即创建</n-button>
+ </template>
+ <n-image :src="brandInfoNotice" width="600"></n-image>
+ </n-popover>
+ </div>
</div>
<template #footer>
<div class="flex justify-end">
- <n-button type="primary" :disabled="canNotUse" @click="createTemplate">{{
- $t("template.createTpl.create") }}</n-button>
+ <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>
</div>
</template>
</n-modal>
</template>
-<script setup lang="ts">
+<script setup lang="tsx">
import { instance } from '@/api'
import { createAiTemplate } from '../pages/AITemplate/controller'
import { useGlobalStore } from '@/store'
+import { checkAiConfiguration } 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 { TemplateStore } from '../pages/AITemplate/dto'
// const store = inject<TemplateStore>('modelStore')!
@@ -46,6 +74,7 @@ const sourceDomain = ref('')
const show = ref(false)
const emits = defineEmits(['confirmType', 'hasCreateTpl'])
const domainList = ref<any>([])
+const aiConfigurationStatus = ref(false)
const computedMethodsList = computed(() => {
if (props.onlyAi) {
@@ -55,8 +84,31 @@ const computedMethodsList = computed(() => {
}
})
+/**
+ * @description Calculate the display of prompt information based on AI configuration, domain name list and other information
+ */
+const noticeShowFlag = computed(() => {
+ if (domainListHasBrandInfo.value.length == 0) {
+ return "domain-list-empty"
+ }
+
+ if (!aiConfigurationStatus.value) {
+ return "ai-configuration-invalid"
+ }
+
+ const domainInfo = domainList.value.find((item: any) => item.domain == sourceDomain.value)
+ if (domainInfo && domainInfo.hasbrandinfo !== 1) {
+ return "invalid-brand-domain"
+ }
+
+ return "normal"
+})
+
+/**
+ * @description Calculate the list of domain names for dropdown options
+ */
const domainListHasBrandInfo = computed(() => {
- return domainList.value.filter((item: any) => item.hasbrandinfo == 1)
+ return domainList.value //.filter((item: any) => item.hasbrandinfo == 1)
})
/**
@@ -72,8 +124,11 @@ const canNotUse = computed(() => {
/**
* @description open modal
*/
-function open() {
- getDomainList()
+async function open() {
+ const res = await checkAiConfiguration() as Record<string, any>
+ aiConfigurationStatus.value = res.is_configured
+ await getDomainList()
+
if (globalStore.domainSource) {
globalStore.domainSource = sourceDomain.value
}
@@ -101,6 +156,51 @@ async function createTemplate() {
emits('confirmType', choosedMethod.value)
}
}
+
+/**
+ * @description Jump to domain and open domain create modal
+ */
+function jumpToDomainCreate() {
+ router.push({
+ name: "Domain",
+ query: {
+ init: "init-domain"
+ }
+ })
+}
+
+/**
+ * @description Jump to ai settings
+ */
+function jumpToAiSettings() {
+ router.push({
+ name: "AiModel"
+ })
+}
+
+/**
+ * @description Jump to domain edit
+ */
+function jumpToDomainEdit() {
+ router.push({
+ name: "EditDomain",
+ params: {
+ domain: sourceDomain.value
+ }
+ })
+}
+
+/**
+ * @description Render select label
+ */
+function renderLabel(option:SelectOption){
+ if(option.hasbrandinfo){
+ return <div><i class="i-domain:brand-info w-4 h-4 mr-1.25"></i> <span>{option.domain}</span></div>
+ }else{
+ return <span>{option.domain}</span>
+ }
+}
+
defineExpose({
open,
close,