|
|
@@ -28,7 +28,7 @@
|
|
|
<el-select v-model="searchForm.sourceType" clearable placeholder="请选择来源类型">
|
|
|
<el-option label="网站" :value="1" />
|
|
|
<el-option label="公众号" :value="2" />
|
|
|
- </el-select>
|
|
|
+ </el-select>
|
|
|
</el-form-item>
|
|
|
</el-col>
|
|
|
<el-col :span="14" class="search-actions">
|
|
|
@@ -69,7 +69,7 @@
|
|
|
<el-table-column prop="fakeId" label="公众号唯一标识" width="150"></el-table-column>
|
|
|
<el-table-column prop="sourceUrl" label="来源网址" min-width="150">
|
|
|
<template #default="scope">
|
|
|
- <el-link :href="scope.row.sourceUrl" target="_blank" :underline="false">
|
|
|
+ <el-link :href="scope.row.sourceUrl" target="_blank" :underline="false">
|
|
|
{{ scope.row.sourceUrl }}
|
|
|
</el-link>
|
|
|
</template>
|
|
|
@@ -99,17 +99,17 @@
|
|
|
|
|
|
<!-- Add/Edit Source Dialog -->
|
|
|
<el-dialog v-model="dialogVisible" :title="isEditing ? '编辑来源' : '添加来源'" width="500px">
|
|
|
- <el-form :model="currentSource" label-width="100px">
|
|
|
- <el-form-item label="名称">
|
|
|
+ <el-form ref="ruleFormRef" :rules="rules" :model="currentSource" label-width="100px">
|
|
|
+ <el-form-item label="名称" prop="sourceName">
|
|
|
<el-input v-model="currentSource.sourceName" placeholder="请输入名称" />
|
|
|
</el-form-item>
|
|
|
- <el-form-item label="类型">
|
|
|
+ <el-form-item label="类型" prop="sourceType">
|
|
|
<el-select v-model="currentSource.sourceType" placeholder="请选择类型">
|
|
|
<el-option label="网站" :value="1" />
|
|
|
<el-option label="公众号" :value="2" />
|
|
|
</el-select>
|
|
|
</el-form-item>
|
|
|
- <el-form-item label="默认分类">
|
|
|
+ <el-form-item label="默认分类" prop="categoryId">
|
|
|
<el-select v-model="currentSource.categoryId" clearable placeholder="请选择默认分类">
|
|
|
<el-option
|
|
|
v-for="category in categories"
|
|
|
@@ -119,13 +119,13 @@
|
|
|
/>
|
|
|
</el-select>
|
|
|
</el-form-item>
|
|
|
- <el-form-item label="链接">
|
|
|
+ <el-form-item label="链接" prop="sourceUrl" v-if="currentSource.sourceType == 1">
|
|
|
<el-input v-model="currentSource.sourceUrl" placeholder="请输入链接" />
|
|
|
</el-form-item>
|
|
|
- <el-form-item label="公众号唯一标识" v-if="currentSource.sourceType==2">
|
|
|
+ <el-form-item label="公众号唯一标识" prop="fakeId" v-if="currentSource.sourceType == 2">
|
|
|
<el-input v-model="currentSource.fakeId" placeholder="请输入公众号唯一标识" />
|
|
|
</el-form-item>
|
|
|
- <el-form-item label="配置方法">
|
|
|
+ <el-form-item label="配置方法" prop="configId">
|
|
|
<el-select v-model="currentSource.configId" clearable placeholder="请选择配置方法">
|
|
|
<el-option
|
|
|
v-for="configuration in configurations"
|
|
|
@@ -135,14 +135,14 @@
|
|
|
/>
|
|
|
</el-select>
|
|
|
</el-form-item>
|
|
|
- <el-form-item label="配置关键词">
|
|
|
+ <el-form-item label="配置关键词" prop="configKey">
|
|
|
<el-input v-model="currentSource.configKey" placeholder="请输入配置关键词" />
|
|
|
</el-form-item>
|
|
|
</el-form>
|
|
|
<template #footer>
|
|
|
<span class="dialog-footer">
|
|
|
<el-button @click="dialogVisible = false">取消</el-button>
|
|
|
- <el-button type="primary" @click="saveSource">保存</el-button>
|
|
|
+ <el-button type="primary" @click="saveSource(ruleFormRef)">保存</el-button>
|
|
|
</span>
|
|
|
</template>
|
|
|
</el-dialog>
|
|
|
@@ -150,11 +150,12 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
-import { ref, onMounted,reactive } from 'vue'
|
|
|
-import { ElMessage, ElMessageBox,ElLoading } from 'element-plus'
|
|
|
+import { ref, onMounted, reactive } from 'vue'
|
|
|
+import { ElMessage, ElMessageBox, ElLoading } from 'element-plus'
|
|
|
import { Link, Plus, Refresh } from '@element-plus/icons-vue'
|
|
|
-import type { Source, Category,Configuration } from '@/types'
|
|
|
-import { sourceApi, categoryApi,configApi } from '@/services/api'
|
|
|
+import type { FormInstance, FormRules } from 'element-plus'
|
|
|
+import type { Source, Category, Configuration } from '@/types'
|
|
|
+import { sourceApi, categoryApi, configApi } from '@/services/api'
|
|
|
|
|
|
// State
|
|
|
const sources = ref<Source[]>([])
|
|
|
@@ -164,6 +165,13 @@ const loading = ref(false)
|
|
|
const dialogVisible = ref(false)
|
|
|
const isEditing = ref(false)
|
|
|
|
|
|
+const ruleFormRef = ref<FormInstance>()
|
|
|
+const rules = reactive<FormRules<Source>>({
|
|
|
+ sourceName: [{ required: true, message: '请输入来源名称', trigger: 'blur' }],
|
|
|
+ sourceType: [{ required: true, message: '请选择来源类型', trigger: 'change' }],
|
|
|
+ fakeId: [{ required: true, message: '请输入公众号唯一标识', trigger: 'change' }],
|
|
|
+ sourceUrl: [{ required: true, message: '请输入链接', trigger: 'change' }],
|
|
|
+})
|
|
|
const currentSource = ref<Source>({
|
|
|
sourceInfoId: null,
|
|
|
sourceName: '',
|
|
|
@@ -174,7 +182,7 @@ const currentSource = ref<Source>({
|
|
|
configId: null,
|
|
|
configValue: '',
|
|
|
configName: '',
|
|
|
- configKey:''
|
|
|
+ configKey: '',
|
|
|
})
|
|
|
|
|
|
const handleSearch = () => {
|
|
|
@@ -201,11 +209,10 @@ const searchForm = reactive({
|
|
|
const pagination = ref({
|
|
|
currentPage: 1,
|
|
|
pageSize: 10,
|
|
|
- total: 0
|
|
|
+ total: 0,
|
|
|
})
|
|
|
|
|
|
const fetchSources = async () => {
|
|
|
-
|
|
|
loading.value = true
|
|
|
try {
|
|
|
// 构造搜索参数
|
|
|
@@ -236,56 +243,60 @@ const fetchCategories = async () => {
|
|
|
|
|
|
const fetchConfigurations = async () => {
|
|
|
try {
|
|
|
- // 获取所有分类,不分页
|
|
|
- const response = await configApi.getConfigurations({})
|
|
|
- configurations.value = response.data
|
|
|
+ // 获取所有分类,不分页
|
|
|
+ const response = await configApi.getConfigurations({})
|
|
|
+ configurations.value = response.data
|
|
|
} catch (error) {
|
|
|
ElMessage.error('获取配置列表失败')
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-const saveSource = async () => {
|
|
|
- try {
|
|
|
- if (!currentSource.value.sourceName || !currentSource.value.sourceUrl) {
|
|
|
- ElMessage.warning('请填写必填项')
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- // Find the category name for the selected category ID
|
|
|
- const selectedCategory = categories.value.find(
|
|
|
- category => category.id === currentSource.value.categoryId
|
|
|
- )
|
|
|
-
|
|
|
- if (!selectedCategory) {
|
|
|
- ElMessage.error('请选择有效的分类')
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- // Add category name to the source object
|
|
|
- const sourceToSave = {
|
|
|
- ...currentSource.value,
|
|
|
- categoryName: selectedCategory.name
|
|
|
- }
|
|
|
- await sourceApi.createSource(sourceToSave)
|
|
|
- if (isEditing.value) {
|
|
|
- ElMessage.success('来源更新成功')
|
|
|
+const saveSource = async (formEl: FormInstance | undefined) => {
|
|
|
+ if (!formEl) return
|
|
|
+ await formEl.validate(async (valid, fields) => {
|
|
|
+ if (valid) {
|
|
|
+ try {
|
|
|
+ let categoryName = ''
|
|
|
+ if (currentSource.value.categoryId) {
|
|
|
+ const selectedCategory = categories.value.find(
|
|
|
+ (category) => category.id === currentSource.value.categoryId
|
|
|
+ )
|
|
|
+ if (!selectedCategory) {
|
|
|
+ ElMessage.error('请选择有效的分类')
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ categoryName = selectedCategory.name
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // Add category name to the source object
|
|
|
+ const sourceToSave = {
|
|
|
+ ...currentSource.value,
|
|
|
+ categoryName: categoryName,
|
|
|
+ }
|
|
|
+ await sourceApi.createSource(sourceToSave)
|
|
|
+ if (isEditing.value) {
|
|
|
+ ElMessage.success('来源更新成功')
|
|
|
+ } else {
|
|
|
+ ElMessage.success('来源添加成功')
|
|
|
+ }
|
|
|
+
|
|
|
+ dialogVisible.value = false
|
|
|
+ fetchSources()
|
|
|
+ } catch (error) {
|
|
|
+ ElMessage.error(isEditing.value ? '更新来源失败' : '添加来源失败')
|
|
|
+ }
|
|
|
} else {
|
|
|
- ElMessage.success('来源添加成功')
|
|
|
+ console.log('error submit!', fields)
|
|
|
}
|
|
|
-
|
|
|
- dialogVisible.value = false
|
|
|
- fetchSources()
|
|
|
- } catch (error) {
|
|
|
- ElMessage.error(isEditing.value ? '更新来源失败' : '添加来源失败')
|
|
|
- }
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
const deleteSource = async (source: Source) => {
|
|
|
try {
|
|
|
await ElMessageBox.confirm('确定要删除该来源吗?', '提示', {
|
|
|
- type: 'warning'
|
|
|
+ type: 'warning',
|
|
|
})
|
|
|
-
|
|
|
+
|
|
|
const params = {
|
|
|
sourceInfoId: source.sourceInfoId,
|
|
|
}
|
|
|
@@ -321,7 +332,7 @@ const showAddDialog = () => {
|
|
|
configId: null,
|
|
|
configValue: '',
|
|
|
configName: '',
|
|
|
- configKey:''
|
|
|
+ configKey: '',
|
|
|
}
|
|
|
isEditing.value = false
|
|
|
dialogVisible.value = true
|
|
|
@@ -341,15 +352,14 @@ onMounted(async () => {
|
|
|
// 并行发起所有请求
|
|
|
const loadingInstance = ElLoading.service({
|
|
|
lock: true,
|
|
|
- });
|
|
|
- try{
|
|
|
- await Promise.all([fetchSources(),fetchCategories(),fetchConfigurations()]);
|
|
|
+ })
|
|
|
+ try {
|
|
|
+ await Promise.all([fetchSources(), fetchCategories(), fetchConfigurations()])
|
|
|
} catch (error) {
|
|
|
- ElMessage.error('请求失败');
|
|
|
+ ElMessage.error('请求失败')
|
|
|
} finally {
|
|
|
- loadingInstance.close();
|
|
|
+ loadingInstance.close()
|
|
|
}
|
|
|
-
|
|
|
})
|
|
|
</script>
|
|
|
|
|
|
@@ -435,4 +445,4 @@ onMounted(async () => {
|
|
|
justify-content: flex-end;
|
|
|
gap: 10px;
|
|
|
}
|
|
|
-</style>
|
|
|
+</style>
|