|
@@ -87,7 +87,7 @@
|
|
|
<span v-else>
|
|
|
<el-button type="primary" @click="onSubmit(ruleFormRef)">保存</el-button>
|
|
|
</span>
|
|
|
- <el-button>取消</el-button>
|
|
|
+ <el-button @click="router.back()">取消</el-button>
|
|
|
</div>
|
|
|
</div>
|
|
|
</template>
|
|
@@ -95,6 +95,7 @@
|
|
|
<script setup lang="ts">
|
|
|
import { useRoute } from 'vue-router'
|
|
|
import axios from 'axios'
|
|
|
+import moment from 'moment'
|
|
|
import { Base64 } from 'js-base64'
|
|
|
import request from '@/config/axios'
|
|
|
import { ElMessage, ElMessageBox, Action, FormRules, FormInstance } from 'element-plus'
|
|
@@ -107,8 +108,9 @@ const initFormData: any = {
|
|
|
description: '',
|
|
|
imgurl: '',
|
|
|
happenTime: '',
|
|
|
+ adddate: '',
|
|
|
sort: 0,
|
|
|
- status: 0, //0 不显示 1 显示
|
|
|
+ status: 1, //0 不显示 1 显示
|
|
|
isTop: 0,
|
|
|
isSyncSite: 1,
|
|
|
content: '',
|
|
@@ -144,7 +146,7 @@ const rules = reactive<
|
|
|
}
|
|
|
})
|
|
|
//同步官网Switch组件
|
|
|
-function beforeChangeHandle() {
|
|
|
+function beforeChangeHandle(): boolean | Promise<boolean> {
|
|
|
const val: number = formData.value.isSyncSite
|
|
|
if (val === 0) return true
|
|
|
return new Promise((resolve, reject) => {
|
|
@@ -169,26 +171,36 @@ function onSubmit(formEl: FormInstance | undefined, num?: number): void {
|
|
|
if (valid) {
|
|
|
let urlApi: string = ''
|
|
|
|
|
|
+ const sendData = {
|
|
|
+ ...formData.value
|
|
|
+ }
|
|
|
if (eTypeRef.value === 'add') {
|
|
|
urlApi = '/adm/article/add'
|
|
|
- if (num === 1) {
|
|
|
- formData.value.happenTime = new Date()
|
|
|
- formData.value.isPub = 1
|
|
|
- }
|
|
|
} else {
|
|
|
urlApi = '/adm/article/update'
|
|
|
}
|
|
|
- request.post({ url: urlApi, data: formData.value }).then((result) => {
|
|
|
+
|
|
|
+ if (formData.value['isPub'] === 0 && num === 1) {
|
|
|
+ sendData['adddate'] = moment().format('YYYY-MM-DD HH:mm:ss')
|
|
|
+ sendData['isPub'] = 1
|
|
|
+ }
|
|
|
+ request.post({ url: urlApi, data: sendData }).then((result) => {
|
|
|
if (result) {
|
|
|
ElMessage({
|
|
|
showClose: true,
|
|
|
message: '保存成功.',
|
|
|
type: 'success'
|
|
|
})
|
|
|
- if (formData.value.isPub === 1 && formData.value.isSyncSite === 1) {
|
|
|
+ if (
|
|
|
+ formData.value['isPub'] === 0 &&
|
|
|
+ sendData['isPub'] === 1 &&
|
|
|
+ formData.value.isSyncSite === 1
|
|
|
+ ) {
|
|
|
syncSiteAjax(formData.value)
|
|
|
}
|
|
|
- router.back()
|
|
|
+ if (num !== 0) {
|
|
|
+ router.back()
|
|
|
+ }
|
|
|
}
|
|
|
})
|
|
|
} else {
|
|
@@ -207,8 +219,7 @@ const syncSiteAjax = async (data): Promise<void> => {
|
|
|
title: data.title,
|
|
|
description: data.description,
|
|
|
imgurl: data.imgurl,
|
|
|
- adddate: data.happenTime,
|
|
|
- sort: data.sort,
|
|
|
+ adddate: data.adddate,
|
|
|
status: data.status,
|
|
|
content: data.content,
|
|
|
seo_title: data.seoTitle,
|