123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- // releaseArticle.vue
- <template>
- <view class="ashome-article">
- <!-- 自定义导航栏 page.json中 设置 "navigationStyle": "custom"-->
- <view class="relase-top" :style="{ marginTop: safeAreaInsets!.top + 'px' }">
- <uni-icons type="closeempty" size="26" @click="closeExchange"></uni-icons>
- <view class="titles">发布文章</view>
- <text></text>
- </view>
- <!-- 发布文章 -->
- <view class="release-article">
- <view class="article-img">
- <uni-file-picker :limit="9" mode="grid" :image-styles="imageStyles" file-mediatype="image" :auto-upload="false"
- @select="selectImage" ref="filePickerRef" v-model="imageList" @delete="deletea"></uni-file-picker>
- </view>
- <!-- 输入标题 -->
- <view class="article-title">
- <input class="title" type="text" placeholder="输入标题更受欢迎哦~" :maxlength="30" v-model="articleTitle"
- @input="inputTitle(1)" />
- </view>
- <!-- 输入文章内容 -->
- <view class="article-content">
- <!-- 富文本 -->
- <richTextEditor v-model:value="articleContent" />
- </view>
- </view>
- <!-- 发布按钮 -->
- <view class="release-btn" hover-class="button-hover" @tap="releaseExchange">
- 发布
- </view>
- </view>
- <uni-popup ref="alertDialogRef" type="dialog">
- <uni-popup-dialog type="info" cancelText="取消" confirmText="确认" title="提示" content="有内容未发布,是否确认退出?"
- @confirm="dialogConfirm"></uni-popup-dialog>
- </uni-popup>
- </template>
- <script setup>
- import {
- ref
- } from 'vue'
- import {
- onLoad
- } from '@dcloudio/uni-app'
- // 图片上传
- import {
- uploadImages
- } from '@/utils/public'
- import richTextEditor from "./richTextEditor.vue"
- // 获取屏幕边界到安全区域距离
- const {
- safeAreaInsets
- } = uni.getSystemInfoSync()
- // 弹出层组件
- const alertDialogRef = ref()
- // 发布文章参数
- const articleParams = ref({})
- // 标题
- const articleTitle = ref < string > ('')
- // 内容
- const articleContent = ref < string > ('')
- // 上传图片组件
- const filePickerRef = ref()
- // 上传完毕后的图片列表
- const imageList = ref([])
- // 上传图标样式
- const imageStyles = ref({
- height: 100, // 边框高度
- width: 100, // 边框宽度
- })
- // 加载
- onLoad((option: any) => {})
- const inputTitle = (type: number) => {
- if (type === 1) {
- // 校验输入的标题,如果字数超过30个,则不能继续输入,然后提示最多只能输入30个字
- if (articleTitle.value.length > 30) {
- uni.showToast({
- title: '最多可输入30个字',
- icon: 'none',
- })
- articleTitle.value = articleTitle.value.substring(0, 30)
- }
- } else {
- if (articleContent.value.length > 1000) {
- uni.showToast({
- title: '最多可输入1000个字',
- icon: 'none',
- })
- articleContent.value = articleContent.value.substring(0, 1000)
- }
- }
- }
- // 关闭发布文章页面
- const closeExchange = () => {
- alertDialogRef.value && alertDialogRef.value.open()
- }
- // 确认关闭
- const dialogConfirm = () => {
- uni.navigateBack({
- delta: 1,
- })
- }
- // 立即发表
- const releaseExchange = async () => {
- // 标题和内容必填
- if (!articleTitle.value || !articleContent.value) {
- uni.showToast({
- title: '标题和内容必填!',
- icon: 'none',
- })
- return
- }
- uni.showToast({
- title: '发布成功',
- icon: 'success',
- })
- setTimeout(() => {
- uni.navigateBack()
- }, 500)
- }
- // 选择完图片
- const selectImage = (e) => {
- const tempFiles = e.tempFiles
- // 处理每张选中的图片
- tempFiles.forEach(async (tempFile) => {
- await uploadImages(tempFile, imageList.value)
- })
- }
- // 删除
- const deletea = (e) => {
- console.log('删除图片', e)
- }
- </script>
- <style scoped lang="scss">
- .ashome-article {
- height: 100%;
- background-color: #fff;
- display: flex;
- flex-direction: column;
- .relase-top {
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding: 0 30rpx;
- height: 100rpx;
- background-color: #fff;
- // border-bottom: 1px solid #f5f5f5;
- color: #3d3d3d;
- font-size: 32rpx;
- .titles {
- font-weight: bold;
- }
- }
- .release-article {
- flex: 1;
- padding: 32rpx;
- .article-img {
- margin-bottom: 20rpx;
- // /deep/ .file-picker__box {}
- :deep(.uni-file-picker) {
- .uni-file-picker__container {
- overflow-x: scroll;
- white-space: nowrap;
- display: block !important;
- .file-picker__box {
- display: inline-block !important;
- .file-picker__box-content {
- .file-picker__progress {
- display: none;
- }
- }
- }
- }
- }
- }
- .article-title {
- margin-bottom: 20rpx;
- .title {
- display: block;
- // height: 46rpx;
- // font-weight: bold;
- font-size: 36rpx;
- }
- }
- .article-content {
- height: 62vh;
- // overflow: auto;
- width: 100%;
- .content {
- // height: calc(100vh - 500rpx);
- height: 100%;
- width: 100%;
- display: block;
- font-size: 28rpx;
- }
- }
- }
- // 发布按钮 固定定到底部
- .release-btn {
- position: fixed;
- bottom: 10%;
- right: 30rpx;
- height: 100rpx;
- width: 100rpx;
- display: flex;
- z-index: 99;
- border-radius: 50%;
- background-color: #a1d8ba;
- font-size: 28rpx;
- font-weight: bold;
- align-items: center;
- justify-content: center;
- color: #fff;
- box-shadow: 0px 0px 8px 0px rgba(0, 0, 0, 0.3) !important;
- }
- .button-hover {
- background-color: #97cbb0;
- }
- }
- </style>
|