first commit
This commit is contained in:
199
pages/find/add.vue
Normal file
199
pages/find/add.vue
Normal file
@@ -0,0 +1,199 @@
|
||||
<template>
|
||||
<view class="findAdd">
|
||||
<view class="findAdd_info">
|
||||
<view style="display: flex; align-items: center; border-bottom: 1rpx solid #eee; padding-bottom: 25rpx">
|
||||
<view style="margin-right: 25rpx; font-size: 30rpx">标题</view>
|
||||
<view style="flex: 1">
|
||||
<up-input height="200" border="none" v-model="formData.title" placeholder="请输入标题"></up-input>
|
||||
</view>
|
||||
</view>
|
||||
<up-textarea height="200" border="none" :maxlength="-1" v-model="formData.content" placeholder="请输入您想要发布的图文"></up-textarea>
|
||||
<up-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple :maxCount="9"></up-upload>
|
||||
<view style="font-size: 24rpx; font-weight: bold; margin: 25rpx 0">#添加话题</view>
|
||||
<view class="findAdd_info_list">
|
||||
<view
|
||||
v-for="(item, index) in formData.topic"
|
||||
:key="index"
|
||||
class="findAdd_info_list_view"
|
||||
:style="{
|
||||
backgroundColor: item.color
|
||||
}"
|
||||
>
|
||||
{{ item.name }}
|
||||
</view>
|
||||
|
||||
<view class="findAdd_info_list_view" style="background-color: rgba(111, 162, 86, 0.1)" @click="addTopic">
|
||||
<up-icon name="plus" size="10"></up-icon>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<button class="confirm-button" @click="submit">发布</button>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue';
|
||||
import { articleAdd, articleDetails, articleUpdate } from '@/api/api.js';
|
||||
import { uploadFiles } from '@/utils/fun.js';
|
||||
import { onLoad } from '@dcloudio/uni-app';
|
||||
let formData = ref({
|
||||
title: '',
|
||||
content: '',
|
||||
topic: [],
|
||||
detailsImageUrl: '',
|
||||
category: 'DISCOVERY',
|
||||
isPublished: 1
|
||||
});
|
||||
|
||||
const fileList1 = ref([]);
|
||||
|
||||
onLoad((options) => {
|
||||
if(options.id){
|
||||
getDetail(options.id);
|
||||
}
|
||||
});
|
||||
|
||||
const getDetail = async (id) => {
|
||||
let _res = await articleDetails({ id });
|
||||
formData.value = _res;
|
||||
if(_res.detailsImageUrl){
|
||||
const imagesUrlArr = _res.detailsImageUrl.split(",")
|
||||
fileList1.value = imagesUrlArr.map(item => ({url:item}))
|
||||
}
|
||||
};
|
||||
|
||||
const submit = () => {
|
||||
formData.value.detailsImageUrl = fileList1.value
|
||||
.map((item, index) => {
|
||||
return item.url;
|
||||
})
|
||||
.join(',');
|
||||
formData.value.coverImageUrl = fileList1.value[0].url;
|
||||
const apiFun = {
|
||||
add: articleAdd,
|
||||
edit: articleUpdate
|
||||
}
|
||||
apiFun[formData.value.id ? "edit" : "add"](formData.value).then((res) => {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '发布成功',
|
||||
showCancel: false,
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
uni.navigateBack();
|
||||
} else if (res.cancel) {
|
||||
console.log('用户点击取消');
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const addTopic = () => {
|
||||
uni.showModal({
|
||||
title: '添加话题',
|
||||
editable: true,
|
||||
placeholderText: '请输入话题',
|
||||
success: function (res) {
|
||||
if (res.confirm) {
|
||||
formData.value.topic.push({
|
||||
color: getRandomLightColor(),
|
||||
name: res.content
|
||||
});
|
||||
console.log(res);
|
||||
} else if (res.cancel) {
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const lightColors = [
|
||||
'rgba(210, 180, 222, 0.1)',
|
||||
'rgba(173, 216, 230, 0.1)',
|
||||
'rgba(255, 182, 193, 0.1)',
|
||||
'rgba(152, 251, 152, 0.1)',
|
||||
'rgba(240, 230, 140, 0.1)',
|
||||
'rgba(216, 191, 216, 0.1)',
|
||||
'rgba(175, 238, 238, 0.1)',
|
||||
'rgba(255, 160, 122, 0.1)',
|
||||
'rgba(221, 160, 221, 0.1)',
|
||||
'rgba(144, 238, 144, 0.1)'
|
||||
];
|
||||
|
||||
// 从数组中随机返回一个颜色的函数
|
||||
function getRandomLightColor() {
|
||||
const randomIndex = Math.floor(Math.random() * lightColors.length);
|
||||
return lightColors[randomIndex];
|
||||
}
|
||||
|
||||
// 删除图片
|
||||
const deletePic = (event) => {
|
||||
fileList1.value.splice(event.index, 1);
|
||||
};
|
||||
|
||||
// 新增图片
|
||||
const afterRead = async (event) => {
|
||||
// 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
|
||||
let lists = [].concat(event.file);
|
||||
let fileListLen = fileList1.value.length;
|
||||
lists.map((item) => {
|
||||
fileList1.value.push({
|
||||
...item,
|
||||
status: 'uploading',
|
||||
message: '上传中'
|
||||
});
|
||||
});
|
||||
for (let i = 0; i < lists.length; i++) {
|
||||
const result = await uploadFiles(lists[i].url);
|
||||
let item = fileList1.value[fileListLen];
|
||||
fileList1.value.splice(fileListLen, 1, {
|
||||
...item,
|
||||
status: 'success',
|
||||
message: '',
|
||||
url: result
|
||||
});
|
||||
fileListLen++;
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
.findAdd {
|
||||
padding: 25rpx;
|
||||
&_info {
|
||||
width: 100%;
|
||||
background: #ffffff;
|
||||
border-radius: 8rpx 8rpx 8rpx 8rpx;
|
||||
padding: 36rpx;
|
||||
|
||||
&_list {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
&_view {
|
||||
margin-right: 20rpx;
|
||||
margin-bottom: 20rpx;
|
||||
padding: 8rpx 30rpx;
|
||||
font-size: 24rpx;
|
||||
border-radius: 28rpx 28rpx 28rpx 28rpx;
|
||||
min-width: 132rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.confirm-button {
|
||||
width: 488rpx;
|
||||
height: 86rpx;
|
||||
background: #6fa256;
|
||||
border-radius: 44rpx 44rpx 44rpx 44rpx;
|
||||
font-size: 26rpx;
|
||||
color: #ffffff;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-top: 332rpx;
|
||||
}
|
||||
</style>
|
||||
120
pages/find/detail.vue
Normal file
120
pages/find/detail.vue
Normal file
@@ -0,0 +1,120 @@
|
||||
<template>
|
||||
<view class="detail-container">
|
||||
<view class="top-area">
|
||||
<view class="picture">
|
||||
<up-avatar size="60rpx" :src="detailData.authorUrl" />
|
||||
</view>
|
||||
<view class="info">
|
||||
<view>
|
||||
{{ detailData.authorName }}
|
||||
</view>
|
||||
<view class="time">
|
||||
{{ detailData.publishTime }}
|
||||
</view>
|
||||
</view>
|
||||
<view class="look">
|
||||
<image src="/static/icon/icon-eye.png"></image>{{ detailData.pageView }}
|
||||
</view>
|
||||
</view>
|
||||
<view class="title">
|
||||
{{ detailData.title }}
|
||||
</view>
|
||||
<view class="content">
|
||||
{{ detailData.content }}
|
||||
</view>
|
||||
<view class="img-area" v-for="(item, index) in detailData?.detailsImageUrl?.split(',')" :key="index">
|
||||
<image mode="widthFix" :src="item"></image>
|
||||
</view>
|
||||
<view class="tags-area">
|
||||
<view
|
||||
class="tag-item"
|
||||
v-for="(item, index) in detailData?.topic"
|
||||
:key="index"
|
||||
:style="{
|
||||
backgroundColor: item.color
|
||||
}"
|
||||
>
|
||||
{{ item.name }}
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive } from 'vue';
|
||||
import { articleDetails } from '@/api/api.js';
|
||||
import { onLoad } from '@dcloudio/uni-app';
|
||||
|
||||
const detailData = ref()
|
||||
|
||||
onLoad((options) => {
|
||||
getDetail(options.id);
|
||||
});
|
||||
|
||||
const getDetail = async (id) => {
|
||||
let _res = await articleDetails({ id });
|
||||
detailData.value = _res;
|
||||
};
|
||||
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.detail-container {
|
||||
padding: 28rpx 30rpx;
|
||||
.top-area {
|
||||
display: flex;
|
||||
font-weight: bold;
|
||||
font-size: 24rpx;
|
||||
color: #232323;
|
||||
.info {
|
||||
margin-left: 12rpx;
|
||||
}
|
||||
.look {
|
||||
margin-left: 36rpx;
|
||||
padding-top: 32rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
image {
|
||||
width: 28rpx;
|
||||
height: 28rpx;
|
||||
margin-right: 4rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
.title {
|
||||
font-weight: bold;
|
||||
font-size: 36rpx;
|
||||
color: #232323;
|
||||
margin-top: 40rpx;
|
||||
}
|
||||
.content {
|
||||
margin-top: 24rpx;
|
||||
font-weight: bold;
|
||||
font-size: 20rpx;
|
||||
color: #232323;
|
||||
}
|
||||
.img-area {
|
||||
margin-top: 24rpx;
|
||||
image {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
.tags-area {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
margin-top: 36rpx;
|
||||
.tag-item {
|
||||
height: 48rpx;
|
||||
line-height: 48rpx;
|
||||
background: #6FA256;
|
||||
border-radius: 24rpx;
|
||||
font-weight: bold;
|
||||
font-size: 20rpx;
|
||||
color: #000;
|
||||
padding: 0 28rpx;
|
||||
margin-right: 24rpx;
|
||||
margin-bottom: 24rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
122
pages/find/find.vue
Normal file
122
pages/find/find.vue
Normal file
@@ -0,0 +1,122 @@
|
||||
<template>
|
||||
<view style="padding: 20rpx 30rpx">
|
||||
<z-paging ref="paging" v-model="dataList" use-page-scroll @query="queryList">
|
||||
<view style="display: flex; flex-wrap: wrap; justify-content: space-between; width: 100%">
|
||||
<view v-for="(item, index) in dataList" :key="index" style="width: 336rpx; background-color: #fff; border-radius: 8rpx 8rpx">
|
||||
<image :src="item.coverImageUrl" style="width: 336rpx; height: 368rpx; border-radius: 8rpx 8rpx 0 0" mode="aspectFill"></image>
|
||||
<view style="padding: 15rpx 15rpx 0; font-size: 24rpx">{{ item.title }}</view>
|
||||
<view style="display: flex; align-items: center; padding: 15rpx; border-radius: 0 0 8rpx 8rpx; font-size: 24rpx">
|
||||
<image :src="item.authorUrl" style="width: 48rpx; height: 48rpx; border-radius: 50%; margin-right: 20rpx"></image>
|
||||
<view>{{ item.authorName }}</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</z-paging>
|
||||
<view
|
||||
style="
|
||||
width: 108rpx;
|
||||
height: 108rpx;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
position: fixed;
|
||||
bottom: 300rpx;
|
||||
right: 30rpx;
|
||||
background: #ffffff;
|
||||
border-radius: 50%;
|
||||
font-size: 24rpx;
|
||||
"
|
||||
@click="navTo('/pages/find/add')"
|
||||
>
|
||||
<image src="/static/image/fawen.png" style="width: 48rpx; height: 48rpx"></image>
|
||||
<view>发文</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
<script setup>
|
||||
import { reactive, ref, onMounted } from 'vue';
|
||||
import { getMerchantSelect } from '@/api/api.js';
|
||||
import { onLoad } from '@dcloudio/uni-app';
|
||||
|
||||
import { useNav } from '@/hooks/useNav.js';
|
||||
|
||||
const { navTo } = useNav();
|
||||
|
||||
onLoad(() => {});
|
||||
const paging = ref(null);
|
||||
const dataList = ref([]);
|
||||
|
||||
const queryList = async (pageNo, pageSize) => {
|
||||
getMerchantSelect({
|
||||
current: pageNo,
|
||||
pageSize: pageSize,
|
||||
category: 'DISCOVERY'
|
||||
})
|
||||
.then((res) => {
|
||||
paging.value.complete(res.records);
|
||||
uni.hideLoading();
|
||||
})
|
||||
.catch((res) => {
|
||||
paging.value.complete(false);
|
||||
uni.hideLoading();
|
||||
});
|
||||
};
|
||||
|
||||
const column = ref(2);
|
||||
|
||||
function loaded() {
|
||||
console.log('加载完成');
|
||||
}
|
||||
|
||||
function wapperClick(item) {
|
||||
console.log('单项点击事件', item);
|
||||
}
|
||||
|
||||
function imageClick(item) {
|
||||
console.log('图片点击事件', item);
|
||||
}
|
||||
const waterfallsFlowRef = ref(null);
|
||||
</script>
|
||||
<style>
|
||||
page {
|
||||
background-color: #f2f5f9;
|
||||
}
|
||||
</style>
|
||||
<style lang="scss" scoped>
|
||||
.handle {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: wrap;
|
||||
margin-bottom: 20rpx;
|
||||
padding: 10rpx;
|
||||
|
||||
.btn {
|
||||
margin: 20rpx 10rpx;
|
||||
padding: 0 20rpx;
|
||||
background: #2878ff;
|
||||
font-size: 28rpx;
|
||||
color: #fff;
|
||||
|
||||
&::after {
|
||||
border: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.item {
|
||||
padding: 10rpx 10rpx 20rpx;
|
||||
background: #fff;
|
||||
|
||||
.title {
|
||||
line-height: 48rpx;
|
||||
font-size: 28rpx;
|
||||
color: #222;
|
||||
}
|
||||
|
||||
.desc {
|
||||
font-size: 24rpx;
|
||||
color: #666;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
186
pages/find/myArticle.vue
Normal file
186
pages/find/myArticle.vue
Normal file
@@ -0,0 +1,186 @@
|
||||
<template>
|
||||
<!-- 我的文章 -->
|
||||
<view class="my-article">
|
||||
<view class="top">
|
||||
<view class="picture">
|
||||
<up-avatar size="180rpx" :src="info.avatar" />
|
||||
</view>
|
||||
<view class="nickname">
|
||||
{{ info.nickName }}
|
||||
</view>
|
||||
<view class="btn-area" @click="toPublish">
|
||||
<image src="/static/icon/publish-article.png"></image>
|
||||
<view class="btn-text">发文</view>
|
||||
</view>
|
||||
</view>
|
||||
<z-paging ref="paging" v-model="listData" use-page-scroll @query="queryList">
|
||||
<view class="list-area">
|
||||
<view class="list-item" v-for="(item, index) in listData" :key="index" @click="goDetail(item)">
|
||||
<view class="list-item-img">
|
||||
<image :src="item.coverImageUrl"></image>
|
||||
</view>
|
||||
<view class="list-item-btm">
|
||||
<view class="list-title">
|
||||
{{ item.content }}
|
||||
</view>
|
||||
<view class="list-btn-area">
|
||||
<view class="bottom-btn" @click.stop="goDelete(item)">
|
||||
<image src="/static/icon/icon-delete.png"></image>
|
||||
<text class="btn-text">删除</text>
|
||||
</view>
|
||||
<view class="bottom-btn ml16" @click.stop="goEdit(item)">
|
||||
<image src="/static/icon/icon-eidt.png"></image>
|
||||
<text class="btn-text">编辑</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</z-paging>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, onMounted } from 'vue';
|
||||
import { getUserArticleList, userInfo, articleDelete } from '@/api/api.js';
|
||||
import { onShow } from '@dcloudio/uni-app';
|
||||
|
||||
const info = ref({});
|
||||
const paging = ref(null);
|
||||
const listData = ref()
|
||||
|
||||
onMounted(async () => {
|
||||
const res = await userInfo();
|
||||
info.value = res;
|
||||
});
|
||||
|
||||
onShow(() => {
|
||||
paging.value && paging.value.reload();
|
||||
})
|
||||
|
||||
const queryList = async (pageNo, pageSize) => {
|
||||
getUserArticleList()
|
||||
.then((res) => {
|
||||
paging.value.complete(res);
|
||||
uni.hideLoading();
|
||||
})
|
||||
.catch((res) => {
|
||||
paging.value.complete(false);
|
||||
uni.hideLoading();
|
||||
});
|
||||
};
|
||||
|
||||
const toPublish = () => {
|
||||
uni.navigateTo({
|
||||
url: `/pages/find/add`
|
||||
});
|
||||
}
|
||||
|
||||
const goDelete = item => {
|
||||
articleDelete([Number(item.id)])
|
||||
.then((res) => {
|
||||
paging.value.reload();
|
||||
});
|
||||
}
|
||||
|
||||
const goEdit = item => {
|
||||
uni.navigateTo({
|
||||
url: `/pages/find/add?id=${item.id}`
|
||||
});
|
||||
}
|
||||
|
||||
const goDetail = item => {
|
||||
uni.navigateTo({
|
||||
url: `/pages/find/detail?id=${item.id}`
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.my-article {
|
||||
.top {
|
||||
height: 342rpx;
|
||||
background: #FFFFFF;
|
||||
position: relative;
|
||||
.picture {
|
||||
padding-top: 40rpx;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
.nickname {
|
||||
font-weight: bold;
|
||||
font-size: 40rpx;
|
||||
color: #232323;
|
||||
margin-top: 20rpx;
|
||||
text-align: center;
|
||||
}
|
||||
.btn-area {
|
||||
position: absolute;
|
||||
top: 40rpx;
|
||||
right: 40rpx;
|
||||
padding: 0 12rpx;
|
||||
image {
|
||||
width: 40rpx;
|
||||
height: 40rpx;
|
||||
}
|
||||
.btn-text {
|
||||
font-weight: bold;
|
||||
font-size: 20rpx;
|
||||
color: #232323;
|
||||
}
|
||||
}
|
||||
}
|
||||
.list-area {
|
||||
padding: 28rpx 30rpx;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-between;
|
||||
.list-item {
|
||||
background: #fff;
|
||||
border-radius: 8rpx;
|
||||
width: 336rpx;
|
||||
margin-bottom: 24rpx;
|
||||
&-img {
|
||||
height: 370rpx;
|
||||
background: #fff;
|
||||
border-radius: 8rpx 8rpx 0 0;
|
||||
image {
|
||||
width: 336rpx;
|
||||
height: 370rpx;
|
||||
}
|
||||
}
|
||||
&-btm {
|
||||
height: 120rpx;
|
||||
padding: 12rpx;
|
||||
.list-title {
|
||||
font-weight: bold;
|
||||
font-size: 24rpx;
|
||||
color: #232323;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.list-btn-area {
|
||||
margin-top: 36rpx;
|
||||
font-weight: 400;
|
||||
font-size: 20rpx;
|
||||
color: #666666;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
.bottom-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
image {
|
||||
width: 28rpx;
|
||||
height: 28rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.ml16 {
|
||||
margin-left: 16rpx;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user