123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276 |
- <template>
- <view class="box">
- <view class="ban_box">
- <view class="tit_box">
- <view class="title">{{ titList.title }}:</view>
- <u--input customStyle="background-color:#ffffff" placeholder="请输入标题" border="surround" v-model.trim="titVal"></u--input>
- </view>
- <view v-if="titList.typeVal" class="tit_box" @click="show = true">
- <view class="title">文章类型:</view>
- <view class="lx">
- <view :style="{ color: typesofs ? '#000' : '#c0c4cc' }">{{ typesofs ? typesofs : '请选择类型' }}</view>
- <u-icon name="arrow-down" color="#c0c4cc" size="20"></u-icon>
- </view>
- </view>
- <view class="tit_box" v-if="titList">
- <view class="title" style="margin-top: -120rpx">{{ titList.content }}:</view>
- <u--textarea v-model.trim="textVal" placeholder="请输入内容"></u--textarea>
- </view>
- <!-- 内容 -->
- <view v-if="titList.typeVal" class="tit_box">
- <view class="title" style="margin-top: -120rpx">文物价值:</view>
- <u--textarea v-model.trim="textVal2" placeholder="请输入内容"></u--textarea>
- </view>
- </view>
- <!-- 图片 -->
- <view class="" style="margin-top: 40rpx">
- <view class="" style="margin-left: 32rpx; margin-bottom: 20rpx">上传图片:{{ uploadNumber + '/' + 9 }}</view>
- <view class="">
- <!-- 上传照片 -->
- <view style="margin-left: 56rpx">
- <u-upload
- width="200rpx"
- height="200rpx"
- :maxCount="9"
- :deletable="true"
- :fileList="fileList1"
- @afterRead="afterRead"
- @delete="deletePic"
- name="1"
- multiple
- ></u-upload>
- </view>
- </view>
- </view>
- <!-- 视频 -->
- <view class="" style="margin-left: 50rpx">
- <view style="margin: 20rpx 0 20rpx -15rpx">请上传视频:</view>
- <u-upload width="200rpx" height="200rpx" :fileList="fileList2" @afterRead="afterRead" @delete="deletePic" name="2" multiple :maxCount="10" accept="video"></u-upload>
- </view>
- <u-picker :show="show" @cancel="show = false" :columns="columns" @close="close" :closeOnClickOverlay="true" @confirm="confirm"></u-picker>
- <view @click="isOk" class="tg_box">{{ titList.okTit }}</view>
- </view>
- </template>
- <script>
- export default {
- name: 'TouGao',
- props: {
- titList: {
- type: Object,
- default: () => {
- return {
- okTit: '投稿',
- title: '文章标题',
- content: '文章内容',
- typeVal: true
- };
- }
- }
- },
- data() {
- return {
- typesofs: '',
- titVal: '',
- textVal: '',
- textVal2: '',
- show: false,
- columns: [['古建筑', '近现代史迹', '古遗址']],
- // 上传的图片
- fileList1: [
- {
- url: 'https://huli-app.wenlvti.net/app_static/minnanhun/image/shouyeTJ.png'
- }
- ]
- };
- },
- computed: {
- uploadNumber() {
- return this.fileList1.length;
- }
- },
- methods: {
- confirm(e) {
- console.log('confirm', e);
- this.typesofs = e.value[0];
- this.show = false;
- },
- async afterRead(event) {
- // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
- let lists = [].concat(event.file);
- let fileListLen = this[`fileList${event.name}`].length;
- lists.map((item) => {
- this[`fileList${event.name}`].push({
- ...item,
- status: 'uploading',
- message: '上传中'
- });
- });
- for (let i = 0; i < lists.length; i++) {
- const result = await this.uploadFilePromise(lists[i].url);
- let item = this[`fileList${event.name}`][fileListLen];
- this[`fileList${event.name}`].splice(
- fileListLen,
- 1,
- Object.assign(item, {
- status: 'success',
- message: '',
- url: result
- })
- );
- fileListLen++;
- }
- },
- // 删除图片
- deletePic(event) {
- console.log(event, 'event');
- this[`fileList${event.name}`].splice(event.index, 1);
- },
- uploadFilePromise(url) {
- return new Promise((resolve, reject) => {
- let a = uni.uploadFile({
- url: 'https://mnhcdn.wenlvti.net/api/minnansoul/content/contribute', // 仅为示例,非真实的接口地址
- filePath: url,
- name: 'file',
- formData: {
- user: 'test'
- },
- success: (res) => {
- setTimeout(() => {
- resolve(res.data.data);
- }, 1000);
- }
- });
- });
- },
- // 投稿
- // isOk() {
- // let titleIsEmpty = this.titleVal === '';
- // let textIsEmpty = this.textVal === '';
- // // 先检查标题和内容是否为空
- // if (titleIsEmpty) {
- // that.$common.errorToShow('请填写投稿标题');
- // return false; // 遇到错误时提前返回,避免后续条件的判断
- // }
- // if (textIsEmpty) {
- // that.$common.errorToShow('请输入投稿内容');
- // return false;
- // }
- // // 再检查模型ID、类型ID和栏目ID
- // if (this.model_id === '' || this.main_body_column_id === '') {
- // that.$common.errorToShow('请选择投稿类型');
- // return false;
- // }
- // // 如果typeId是必须选择的,这里也要进行验证
- // if (this.typeId === '') {
- // that.$common.errorToShow('请选择内容类型');
- // return false;
- // } else {
- // this.$api.contribute(
- // {
- // main_body_id: this.main_body_id,
- // model_id: this.model_id,
- // main_body_column_id: this.main_body_column_id,
- // title: this.titleVal,
- // type: this.typeId,
- // content: this.titleVal
- // },
- // function (res) {
- // if (res.code == 1) {
- // that.$common.successToShow('投稿成功');
- // // console.log(res, 6666);
- // } else {
- // that.$common.errorToShow('投稿失败请稍后再试');
- // }
- // }
- // );
- // }
- // },
- close() {
- this.show = false;
- }
- }
- };
- </script>
- <style>
- .img {
- width: 100%;
- height: 100%;
- border-radius: 50%;
- }
- .fk_box {
- width: 90%;
- display: flex;
- justify-content: space-between;
- margin: auto;
- margin-top: 20rpx;
- font-size: 30rpx;
- color: #313131;
- text-align: center;
- }
- .jianyi {
- width: 170rpx;
- height: 60rpx;
- line-height: 58rpx;
- border: 2rpx solid #fadcb3;
- background-color: #fdf7ee;
- border-radius: 10rpx;
- }
- /deep/.u-input--radius.data-v-113bc24f,
- .u-input--square.data-v-113bc24f {
- background-color: #ffffff !important;
- }
- /deep/.u-input.data-v-113bc24f {
- background-color: #ffffff !important;
- }
- .ban_box {
- width: 90%;
- margin: auto;
- margin-top: 40rpx;
- }
- .tit_box {
- width: 680rpx;
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-top: 40rpx;
- }
- .title {
- margin-right: 10rpx;
- font-size: 30rpx;
- color: #313131;
- }
- .lx {
- display: flex;
- justify-content: space-between;
- width: 540rpx;
- height: 70rpx;
- background-color: #ffffff;
- border-radius: 10rpx;
- line-height: 70rpx;
- color: #c0c4cc;
- padding-left: 20rpx;
- padding-right: 20rpx;
- }
- .tg_box {
- width: 390rpx;
- height: 74rpx;
- margin: auto;
- margin-top: 40rpx;
- font-size: 34rpx;
- background-color: #f5c382;
- text-align: center;
- font-weight: bold;
- color: #313131;
- border-radius: 10rpx;
- line-height: 74rpx;
- }
- </style>
|