Files
jjx-wap/pages/school/add.vue
T
2026-10-08 18:34:09 +08:00

151 lines
5.2 KiB
Vue

<template>
<view class="wrap">
<uititle title="金久信学堂"></uititle>
<view class="bg-white p-10">
<view class="group flex align-center m-top-30">
<view class="lb need m-right-20">标题:</view>
<view class="vl flex-1">
<u--input
placeholder="请输入标题"
border="surround"
v-model="formData.name"
/>
</view>
</view>
<view class="group flex align-center m-top-30">
<view class="lb need m-right-20">分类:</view>
<view class="vl flex-1" @click="showPicker = true">
<u--input
style="pointer-events:none"
disabledColor="#fff"
disabled
placeholder="请选择分类"
border="surround"
v-model="cate"
/>
</view>
</view>
<view class="group m-top-20">
<view class="lb m-right-20">附件:</view>
<view class="m-top-30">
<u-upload
accept="file"
:fileList="formData.files"
@afterRead="afterRead"
:maxCount="1"
:previewImage="false"
>
<view class="w-100p">
<view>
<u-button size="mini" type="primary">点击上传</u-button>
</view>
<view class="mt-10 flex justify-between items-center w-100p" @click="delFiles(index)"
v-for="(item, index) in fileNameList" :key="index">
<text>{{ item }}</text>
<u-icon name="trash"/>
</view>
</view>
</u-upload>
</view>
</view>
<view class="lb need m-right-20 mt-20 border-top">内容:</view>
<piaoyiEditor :values="formData.content" :maxlength="99999" @changes="saveContents" :readOnly="false"/>
<u-button class="m-top-30" type="primary" text="提交" @click="save"></u-button>
</view>
<u-picker :show="showPicker" :columns="[cateList]" keyName="name"
@cancel="showPicker = false" @close="showPicker = false" closeOnClickOverlay
@confirm="confirmCate"/>
</view>
</template>
<script>
import uititle from '@/components/common/title'
import cmsearch from '@/components/common/search'
import cmempty from '@/components/common/empty'
import piaoyiEditor from '@/uni_modules/piaoyi-editor/components/piaoyi-editor/piaoyi-editor.vue';
import dayjs from "dayjs";
import md5 from "js-md5";
export default {
components: {
uititle,
cmsearch,
cmempty,
piaoyiEditor,
},
data() {
return {
editor: null,
toolbarConfig: {},
editorConfig: {placeholder: '请输入内容...'},
mode: 'default',
formData: {
name: null,
files: [],
parentId: null,
content: '',
},
cateList: [],
fileNameList: [],
showPicker: false,
cate: ''
}
},
methods: {
async getCateList() {
const {rows} = await vk.callFunction({
url: 'client/article/category/pub/getList'
})
this.cateList = rows
},
async save() {
if (!this.formData.name) return vk.toast('标题不能为空')
if (!this.formData.parentId) return vk.toast('分类不能为空')
if (!this.formData.content) return vk.toast('内容不能为空')
await vk.callFunction({
url: 'client/article/list/kh/add',
data: this.formData
})
vk.navigateBack()
},
saveContents({html}) {
this.formData.content = html
},
afterRead({file}) {
if (!file) return
uniCloud.uploadFile({
filePath: file.url,
cloudPath: dayjs().format('YYYY/MM/DD') + '/' + md5(file.name + Date.now().toString()) + '.pdf',
success: ({fileID}) => {
uniCloud.getTempFileURL({
fileList: [fileID]
}).then(res => {
this.formData.files.push(res.fileList[0].tempFileURL)
this.fileNameList.push(file.name)
})
}
})
},
confirmCate({value}) {
this.formData.parentId = value[0]._id
this.cate = value[0].name
this.showPicker = false
},
delFiles(index){
this.formData.files.splice(index, 1)
this.fileNameList.splice(index, 1)
}
},
onShow() {
this.getCateList()
}
}
</script>
<style lang="scss">
page {
background: #f7f7f7;
}
</style>