|
|
@ -12,8 +12,8 @@ |
|
|
|
</a-space> |
|
|
|
</div> |
|
|
|
<div class="modal"> |
|
|
|
<a-modal v-model:open="formControl.open" title="Basic Modal" width="100%" wrap-class-name="full-modal" |
|
|
|
@ok="onSubmit" ok-text="确认" cancel-text="取消"> |
|
|
|
<a-modal v-model:open="formControl.open" :title="delControl.title" width="100%" wrap-class-name="full-modal" |
|
|
|
@ok="onSubmit" ok-text="确认" cancel-text="取消" @cancel="unControl(delControl.title)"> |
|
|
|
<a-form ref="formRef" :model="formState" :rules="rules"> |
|
|
|
<a-flex gap="large" justify="space-between"> |
|
|
|
<a-form-item label="日记标题" name="diarytitle"> |
|
|
@ -26,24 +26,22 @@ |
|
|
|
typeItem.typename }}</a-select-option> |
|
|
|
</a-select> |
|
|
|
</a-form-item> |
|
|
|
<a-form-item name="labelname" label="标签名称" class="items"> |
|
|
|
<a-select v-model:value="formState.labelnames" mode="multiple" placeholder="请选择标签"> |
|
|
|
<a-select-option :value="label.id" v-for="label in labellist">{{ label.labelname |
|
|
|
}}</a-select-option> |
|
|
|
</a-select> |
|
|
|
</a-form-item> |
|
|
|
|
|
|
|
<a-form-item label="文图地址" name="imglink" class="items"> |
|
|
|
<a-input v-model:value="formState.imglink" placeholder="请输入文图地址" /> |
|
|
|
</a-form-item> |
|
|
|
</a-flex> |
|
|
|
<v-md-editor v-model="formState.diarycontent" height="800px" |
|
|
|
left-toolbar="undo redo clear | h bold italic strikethrough quote | ul ol table hr | link image code | save | tip | emoji" |
|
|
|
></v-md-editor> |
|
|
|
left-toolbar="undo redo clear | h bold italic strikethrough quote | ul ol table hr | link image code | save | tip | emoji"></v-md-editor> |
|
|
|
<a-form-item label="日记备注" name="descr" class="desrpad"> |
|
|
|
<a-textarea v-model:value="formState.descr" /> |
|
|
|
</a-form-item> |
|
|
|
</a-form> |
|
|
|
</a-modal> |
|
|
|
<a-modal v-model:open="delControl.open" title="提示" @ok="del" ok-text="确认" cancel-text="取消" |
|
|
|
@cancel="unControl('删除')"> |
|
|
|
<p>确认删除吗?</p> |
|
|
|
</a-modal> |
|
|
|
</div> |
|
|
|
<div class="table"> |
|
|
|
<a-table bordered :data-source="diarylist" :columns="columns"> |
|
|
@ -59,14 +57,9 @@ |
|
|
|
<a-space> |
|
|
|
<div> |
|
|
|
<a-button size="small" danger @click="delModal(record.id)">删除</a-button> |
|
|
|
<a-modal v-model:open="open" title="提示" @ok="ackDelete(record)" ok-text="确认" |
|
|
|
cancel-text="取消" @cancel="unDelete"> |
|
|
|
<p>确认删除吗?</p> |
|
|
|
</a-modal> |
|
|
|
|
|
|
|
</div> |
|
|
|
<a-button size="small" type="primary" ghost @click="editModal(record.id)">{{ record.id |
|
|
|
}}编辑</a-button> |
|
|
|
<a-button size="small" type="primary" ghost @click="ackWatch(record)">预览</a-button> |
|
|
|
<a-button size="small" type="primary" ghost @click="editModal(record.id)">编辑</a-button> |
|
|
|
</a-space> |
|
|
|
</template> |
|
|
|
</template> |
|
|
@ -84,7 +77,7 @@ import type { Rule } from 'ant-design-vue/es/form'; |
|
|
|
import { useRouter } from "vue-router" |
|
|
|
import { message } from 'ant-design-vue'; |
|
|
|
import type { diaryInterface } from "@/api/admin" |
|
|
|
import { get, post, put } from "@/tools/request" |
|
|
|
import { get, post, put,remove } from "@/tools/request" |
|
|
|
import { diaryStore } from '@/stores'; |
|
|
|
import type { labelInterface, typeInterface } from "@/api/admin" |
|
|
|
dayjs.locale('zh-cn'); |
|
|
@ -110,7 +103,7 @@ const onChange = (date: string, dateString: string[]) => { |
|
|
|
|
|
|
|
const search = async () => { |
|
|
|
try { |
|
|
|
const response = await get("/diarys/list/search", { |
|
|
|
const response = await get("/diarys/search", { |
|
|
|
diarytitle: searchlist.diarytitle, |
|
|
|
typename: searchlist.typename, |
|
|
|
start_date: searchlist.start_date, |
|
|
@ -136,6 +129,9 @@ const search = async () => { |
|
|
|
console.error("request is exception", error); |
|
|
|
} |
|
|
|
}; |
|
|
|
const unControl = (text: string) => { |
|
|
|
message.warn(`取消${text}`) |
|
|
|
} |
|
|
|
|
|
|
|
const formState = ref({ |
|
|
|
id: '', |
|
|
@ -146,7 +142,17 @@ const formState = ref({ |
|
|
|
descr: '', |
|
|
|
imglink: "" |
|
|
|
}); |
|
|
|
|
|
|
|
const resetFormState = () => { |
|
|
|
formState.value = { |
|
|
|
id: '', |
|
|
|
diarytitle: '', |
|
|
|
typeid: null, |
|
|
|
diarycontent: "", |
|
|
|
labelnames: [], |
|
|
|
descr: '', |
|
|
|
imglink: "" |
|
|
|
} |
|
|
|
} |
|
|
|
const typelist = ref<typeInterface[]>([]) |
|
|
|
const typeList = async () => { |
|
|
|
try { |
|
|
@ -176,24 +182,26 @@ const rules: Record<string, Rule[]> = { |
|
|
|
], |
|
|
|
}; |
|
|
|
|
|
|
|
const formControl=ref({ |
|
|
|
open:false, |
|
|
|
ids:null |
|
|
|
const formControl = ref({ |
|
|
|
open: false, |
|
|
|
ids: null |
|
|
|
}) |
|
|
|
|
|
|
|
const formRef = ref(); |
|
|
|
const addModal = () => { |
|
|
|
delControl.title = "新增" |
|
|
|
formControl.value.open = true |
|
|
|
console.log(formControl.value.ids) |
|
|
|
resetFormState() |
|
|
|
} |
|
|
|
|
|
|
|
const editModal = (id: any) => { |
|
|
|
delControl.title = "编辑" |
|
|
|
formControl.value.ids = id |
|
|
|
formControl.value.open = true |
|
|
|
get( |
|
|
|
`/diarys/list/search/${id}` |
|
|
|
).then(response=>{ |
|
|
|
formState.value=response.data.data |
|
|
|
).then(response => { |
|
|
|
formState.value = response.data.data |
|
|
|
|
|
|
|
}) |
|
|
|
console.log(formControl.value.ids) |
|
|
@ -202,33 +210,29 @@ const onSubmit = () => { |
|
|
|
formRef.value |
|
|
|
.validate() |
|
|
|
.then(async () => { |
|
|
|
const labels = formState.value.labelnames.map(labelId => { |
|
|
|
const label = labellist.value.find((label: any) => label.id === labelId); |
|
|
|
return label ? { "id": label.id, "labelname": label.labelname, "descr": label.descr } : null; |
|
|
|
}); |
|
|
|
if (formState.value.diarycontent === "" || formState.value.diarycontent.trim() === "") { |
|
|
|
message.error("日记内容不能为空") |
|
|
|
return; |
|
|
|
} |
|
|
|
const formdata = { |
|
|
|
diary: { |
|
|
|
diarytitle: formState.value.diarytitle, |
|
|
|
typeid: formState.value.typeid, |
|
|
|
imglink: formState.value.imglink, |
|
|
|
diarycontent: formState.value.diarycontent, |
|
|
|
descr: formState.value.descr |
|
|
|
}, |
|
|
|
labels: labels |
|
|
|
} |
|
|
|
if (formControl.value.ids) { |
|
|
|
await put(`/diarys/update/${formControl.value.ids}`, formdata) |
|
|
|
formControl.value.open=false, |
|
|
|
formControl.value.open = false, |
|
|
|
diaryList() |
|
|
|
} else { |
|
|
|
await post('/diarys/add', formdata); |
|
|
|
formControl.value.open=false, |
|
|
|
formControl.value.open = false, |
|
|
|
diaryList() |
|
|
|
} |
|
|
|
}) |
|
|
|
}; |
|
|
|
|
|
|
|
const open = ref<boolean>(false); |
|
|
|
|
|
|
|
const delModal = (id: any) => { |
|
|
|
delControl.open = true; |
|
|
@ -253,7 +257,7 @@ const diaryList = async () => { |
|
|
|
diarycontent: items.diarycontent, |
|
|
|
typename: items.typename, |
|
|
|
})) |
|
|
|
console.log(`output->diarylist`,diarylist) |
|
|
|
console.log(`output->diarylist`, diarylist) |
|
|
|
} else { |
|
|
|
console.log("diarylist is not exits") |
|
|
|
} |
|
|
@ -273,29 +277,25 @@ const labelfilter = (labelnames: any) => { |
|
|
|
} |
|
|
|
return Array.isArray(labels) ? labels.filter(label => label && label.trim() !== '') : []; |
|
|
|
} |
|
|
|
// 日记删除 |
|
|
|
// const ackDelete = async (record:{key:string,id:number}) => { |
|
|
|
// remove(`/diarys/delete/${toDelete.id}`).then((response) => { |
|
|
|
// if (response.status === 200) { |
|
|
|
// dataSource.value = dataSource.value.filter(item => item.key !== record.key); |
|
|
|
// open.value = false; |
|
|
|
// } |
|
|
|
// message.info("删除成功") |
|
|
|
// }).catch(error => { |
|
|
|
// console.error('There was an error deleting the diary!', error); |
|
|
|
// }) |
|
|
|
// }; |
|
|
|
// 日记修改 |
|
|
|
|
|
|
|
const ackUpdate = async (id: any) => { |
|
|
|
router.push(`/admin/diarymanage/update/${id}`); |
|
|
|
}; |
|
|
|
const ackWatch = async (record: { key: string, id: number }) => { |
|
|
|
router.push(`/admin/diarymanage/watch`); |
|
|
|
} |
|
|
|
const unDelete = async () => { |
|
|
|
message.warn("取消删除") |
|
|
|
const del = async (id: any) => { |
|
|
|
id = delControl.ids |
|
|
|
try { |
|
|
|
if (id) { |
|
|
|
await remove( |
|
|
|
`/diarys/delete/${id}` |
|
|
|
) |
|
|
|
diaryList() |
|
|
|
} else { |
|
|
|
console.log("id do not exist!") |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
console.log("interface request exception") |
|
|
|
} |
|
|
|
|
|
|
|
delControl.open = false |
|
|
|
} |
|
|
|
|
|
|
|
const columns = [ |
|
|
|
{ |
|
|
|
title: '序号', |
|
|
|