Commit 734d6e7d authored by mengcuiguang's avatar mengcuiguang

代码优化

parent 1d791d1a
......@@ -32,14 +32,7 @@
"navigationBarBackgroundColor": "#2196f3",
"navigationBarTextStyle": "black"
}
}, {
"path": "pages/index/productIndex",
"style": {
"navigationStyle": "custom",
"navigationBarBackgroundColor": "#2196f3",
"navigationBarTextStyle": "black"
}
},
},
{
"path": "pages/my/my",
"style": {
......@@ -61,13 +54,6 @@
"navigationBarBackgroundColor": "#2196f3",
"navigationBarTextStyle": "black"
}
}, {
"path": "pages/moments/moments",
"style": {
"navigationStyle": "custom",
"navigationBarBackgroundColor": "#2196f3",
"navigationBarTextStyle": "black"
}
}
],
// 分包配置
......@@ -81,24 +67,6 @@
"navigationBarTextStyle": "black"
}
}]
}, {
"root": "pagesB",
"pages": [{
"path": "moments/add",
"style": {
"navigationStyle": "custom",
"navigationBarBackgroundColor": "#2196f3",
"navigationBarTextStyle": "black"
}
}, {
"path": "moments/video-detail",
"style": {
"navigationStyle": "custom",
"navigationBarBackgroundColor": "#2196f3",
"navigationBarTextStyle": "black"
}
}]
}, {
"root": "pagesC",
"pages": [{
......@@ -136,10 +104,6 @@
"network": "all", //在指定网络下预下载,可选值为:all(不限网络)、wifi(仅wifi下预下载)
"packages": ["pagesA"] //进入页面后预下载分包
},
"pages/moments/moments": {
"network": "all", //在指定网络下预下载,可选值为:all(不限网络)、wifi(仅wifi下预下载)
"packages": ["pagesB"] //进入页面后预下载分包
},
"pages/spread/spread": {
"network": "all", //在指定网络下预下载,可选值为:all(不限网络)、wifi(仅wifi下预下载)
"packages": ["pagesC"] //进入页面后预下载分包
......
<template>
<view class="body">
<view style="height: 100%;">
<indexPage v-if="fromType==1" v-show="currentPage==0" ref="index" />
<productIndexPage v-else v-show="currentPage==0" ref="productIndex" />
<momentsPage v-if="buyerShowEnable==1" v-show="currentPage==1" ref="moments" />
<spreadPage v-if="promotionEnable==1" v-show="currentPage==2" ref="spread" />
<userPage v-show="currentPage==3" ref="user" />
<indexPage v-show="currentPage==0" ref="index" />
<spreadPage v-show="currentPage==1" ref="spread" />
<userPage v-show="currentPage==2" ref="user" />
</view>
<view class="tabs-bar">
<view :class="currentPage==0?'tab active': 'tab'" :style="'padding-bottom:' + bottomSafePadding + 'px;'"
......@@ -16,40 +14,27 @@
</image>
<image v-else class="tabs-image" src="/static/tab/index_unselected.png" mode="heightFix"></image>
</view>
首页
剧场
</view>
<view v-if="buyerShowEnable==1" :class="currentPage == 1?'tab active': 'tab'"
<view :class="currentPage == 1?'tab active': 'tab'"
:style="'padding-bottom:' + bottomSafePadding + 'px;'" @click="tabChange(1)">
<view style="margin: 16rpx 0 11rpx;">
<image v-if="currentPage==1" class="tabs-image" src="/static/tab/moments_selected.png"
mode="heightFix"></image>
<image v-else class="tabs-image" src="/static/tab/moments_unselected.png" mode="heightFix">
</image>
</view>
买家秀
</view>
<view v-if="promotionEnable==1" :class="currentPage == 2?'tab active': 'tab'"
:style="'padding-bottom:' + bottomSafePadding + 'px;'" @click="tabChange(2)">
<view style="margin: 16rpx 0 11rpx;">
<image v-if="currentPage==2" class="tabs-image" src="/static/tab/promote_selected.png"
<image v-if="currentPage==1" class="tabs-image" src="/static/tab/promote_selected.png"
mode="heightFix"></image>
<image v-else class="tabs-image" src="/static/tab/promote_unselected.png" mode="heightFix"></image>
</view>
广
</view>
<view :class="currentPage == 3?'tab active': 'tab'" :style="'padding-bottom:' + bottomSafePadding + 'px;'"
@click="tabChange(3)">
<view :class="currentPage == 2?'tab active': 'tab'" :style="'padding-bottom:' + bottomSafePadding + 'px;'"
@click="tabChange(2)">
<view style="margin: 16rpx 0 11rpx;">
<image v-if="currentPage==3" class="tabs-image" src="/static/tab/my_selected.png" mode="heightFix">
<image v-if="currentPage==2" class="tabs-image" src="/static/tab/my_selected.png" mode="heightFix">
</image>
<image v-else class="tabs-image" src="/static/tab/my_unselected.png" mode="heightFix"></image>
</view>
我的
</view>
</view>
<coupon-new :couponResult="couponResult" :showModal="showCoupon" @confirm="confirm">
</coupon-new>
</view>
......@@ -64,9 +49,7 @@
const app = getApp();
// 首页
import productIndexPage from "@/pages/index/productIndex.vue";
import indexPage from "@/pages/index/index.vue";
import momentsPage from "@/pages/moments/moments.vue";
import spreadPage from "@/pages/spread/spread.vue";
import userPage from "@/pages/my/my.vue";
......@@ -75,8 +58,6 @@
mixins: [common],
components: {
indexPage,
productIndexPage,
momentsPage,
spreadPage,
userPage
},
......@@ -117,16 +98,10 @@
try {
// 在子组件重写show()代替onShow()
if (this.currentPage == 0) {
if (this.fromType == 0) {
this.$refs.productIndex.show();
} else if (this.fromType == 1) {
this.$refs.index.show();
}
this.$refs.index.show();
} else if (this.currentPage == 1) {
this.$refs.moments.show(this.fromType);
} else if (this.currentPage == 2) {
this.$refs.spread.show();
} else if (this.currentPage == 3) {
} else if (this.currentPage == 2) {
this.$refs.user.show();
}
} catch (e) {
......@@ -149,16 +124,10 @@
},
loadComponentData() {
if (this.currentPage == 0) {
if (this.fromType == 0) {
this.$refs.productIndex.show();
} else {
this.$refs.index.show();
}
this.$refs.index.show();
} else if (this.currentPage == 1) {
this.$refs.moments.show(this.fromType);
} else if (this.currentPage == 2) {
this.$refs.spread.show();
} else if (this.currentPage == 3) {
} else if (this.currentPage == 2) {
this.$refs.user.show();
}
},
......
This diff is collapsed.
<template>
<view class="body">
<status-title :showBack="showBack==1">Companionx</status-title>
<view class="title mt-20 ml-26">
<view class="line"></view>
爆款推荐
</view>
<z-paging class="flex-1 m-20" ref="paging" v-model="dataList" @query="queryList">
<view style="column-count: 2;column-gap: 0;">
<view class="item-wrap" v-for="(item, i) in dataList" :key="i" v-if="i % 2 == 0"
@click="handleInfo(item)">
<image class="img" :src="item.url" mode="aspectFill"></image>
<view class="ml-10">
<u-text color="#000" :text="item.title" size="18" :lines="1"></u-text>
</view>
<view class="flex pd-10">
<view style="color: #F8425A;font-size: 28rpx;">到手价¥</view>
<view style="color: #F8425A;font-size: 32rpx;">{{item.price}}</view>
<view style="color: #ADADAD;font-size: 26rpx;margin-left: auto;">{{'已售'+item.sellNum}}</view>
</view>
</view>
<view class="item-wrap" v-for="(item, i) in dataList" :key="i" v-if="i % 2 == 1"
@click="handleInfo(item)">
<image class="img" :src="item.url" mode="aspectFill"></image>
<view class="ml-10">
<u-text color="#000" :text="item.title" size="18" :lines="1"></u-text>
</view>
<view class="flex pd-10">
<view style="color: #F8425A;font-size: 28rpx;">到手价¥</view>
<view style="color: #F8425A;font-size: 32rpx;">{{item.price}}</view>
<view style="color: #ADADAD;font-size: 26rpx;margin-left: auto;">{{'已售'+item.sellNum}}</view>
</view>
</view>
</view>
</z-paging>
</view>
</template>
<script>
import common from '@/mixins/common';
import {
navigateTo,
message,
alert,
loading
} from '@/utils/fun.js';
const app = getApp();
export default {
name: 'index',
mixins: [common],
data() {
return {
showBack: 0,
dataList: []
};
},
onLoad(options) {
this.showBack = options.back ?? 0
},
methods: {
show() {
if (this.$refs.paging != null) {
this.$refs.paging.refresh();
}
},
queryList(page, size) {
this.post({
url: '/app/getHomeSkuList',
data: {
page: page,
size: size,
session: app.globalData.token
},
showLoading: true,
success: ({
data
}) => {
this.dataList = data.list
this.$refs.paging.complete(this.dataList);
}
});
},
handleInfo(item) {
navigateTo(`/pagesA/product/product?data=` + encodeURIComponent(JSON.stringify(item)))
},
}
};
</script>
<style lang="scss">
.body {
// background-color: white;
}
.title {
display: flex;
flex-direction: row;
align-items: center;
font-size: 40rpx;
font-weight: 700;
.line {
width: 6rpx;
background-color: red;
height: 40rpx;
margin-right: 16rpx;
}
}
.item-wrap {
width: 96%;
border-radius: 10rpx;
background-color: #fff;
break-inside: avoid;
margin-bottom: 20rpx;
height: 490rpx;
.img {
position: relative;
border-radius: 10rpx;
width: 100%;
height: 360rpx;
}
}
</style>
<template>
<view class="body">
<status-title :showBack="false">买家秀</status-title>
<view v-if="fromType==1" class="tabContainer">
<v-tabs height="60rpx" bgColor="#E3E4E8" v-model="tabIndex" :pills="true" pillsBorderRadius="50rpx"
pillsColor="#fff" line-height="0" color="#313131" activeColor="#CD4346" :tabs="tabs"
@change="handleChange" />
</view>
<swiper style="height: 100%;" :current="tabIndex" @change="e => tabIndex = e.detail.current">
<swiper-item>
<z-paging style="height: 100%;" ref="paging" v-model="picData" @query="queryList">
<post-list :list="picData" />
</z-paging>
</swiper-item>
<swiper-item v-if="fromType==1">
<z-paging style="height: 100%;" ref="paging2" v-model="videoData" @query="queryList2">
<post-list :list="videoData" />
</z-paging>
</swiper-item>
</swiper>
<view @click="showAddPopup = !showAddPopup" class="addCircle">
<image mode="widthFix" class="icon-add" src="/static/moments/add.png"></image>
</view>
<!-- 发布弹窗 -->
<u-popup :show="showAddPopup" mode="bottom" round="20rpx" :closeOnClickOverlay="true"
@close="showAddPopup = false">
<view class="handle-wrap">
<view @click="handleJump(item)" class="item" v-for="(item, index) in addPopup" :key="index">
<image mode="widthFix" class="icon" :src="item.icon"></image>
<text class="txt">{{ item.text }}</text>
</view>
</view>
<view class="handle-close">
<u-icon @click="showAddPopup = false" size="22" name="close"></u-icon>
</view>
</u-popup>
</view>
</template>
<script>
import common from '@/mixins/common';
import postList from '../../components/post-list/post-list.vue';
const app = getApp();
import {
navigateTo,
} from '@/utils/fun.js';
export default {
components: {
postList
},
mixins: [common],
data() {
return {
fromType: 0,
showAddPopup: false,
tabIndex: -1,
tabs: [
'买家秀',
'福利'
],
addPopup: [{
icon: '/static/moments/h_2.png',
text: '图文',
url: '/pagesB/moments/add?type=1'
},
{
icon: '/static/moments/h_3.png',
text: '视频',
url: '/pagesB/moments/add?type=2'
}
],
picData: [],
videoData: [],
}
},
methods: {
show(val) {
this.fromType = val
if (this.tabIndex == -1) {
this.tabIndex = 0
}
if (this.tabIndex == 0) {
this.$refs.paging.refresh();
} else if (this.tabIndex == 1) {
this.$refs.paging2.refresh();
}
},
queryList(page, size) {
this.post({
url: '/comment/list',
data: {
type: 0,
page: page,
size: size,
session: app.globalData.token,
},
showLoading: true,
success: ({
data
}) => {
this.$refs.paging.complete(data.list)
}
})
},
queryList2(page, size) {
this.post({
url: '/comment/list',
data: {
type: 1,
page: page,
size: size,
session: app.globalData.token,
},
showLoading: true,
success: ({
data
}) => {
this.$refs.paging2.complete(data.list)
}
})
},
handleChange(index) {
this.tabIndex = index;
// if (this.tabIndex == 0) {
// this.$refs.paging.clear();
// this.$refs.paging.reload();
// } else {
// this.$refs.paging2.clear();
// this.$refs.paging2.reload();
// }
},
handleJump(e) {
uni.navigateTo({
url: e.url
});
this.showAddPopup = false;
},
}
}
</script>
<style lang="scss">
.body {
background-color: #f5f5f5;
.tabContainer {
display: flex;
justify-content: center;
align-items: center;
background-color: #E3E4E8;
margin: 10rpx auto;
padding: 0 20rpx;
border-radius: 50rpx;
.v-tabs {
margin-top: 10rpx;
height: 70rpx;
}
}
// 发布弹出框
.handle-wrap {
height: 200rpx;
display: flex;
padding: 50rpx 0;
.item {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
flex: 1;
padding: 20rpx 0;
border-radius: 20rpx;
.icon {
width: 100rpx;
height: 100rpx;
margin-bottom: 20rpx;
}
.txt {
font-size: 32rpx;
}
}
}
.handle-close {
display: flex;
justify-content: center;
margin-bottom: 50rpx;
}
.addCircle {
z-index: 100;
position: fixed;
left: 50%;
top: 84%;
transform: translate(-50%, -50%);
/*50%为自身尺寸的一半*/
}
.icon-add {
width: 100rpx;
// height: 90rpx;
// box-shadow: 0 0 6rpx rgba(0, 0, 0, 0.6);
}
}
</style>
This diff is collapsed.
<template>
<view class="body">
<status-title :showBack="true">{{(form.type==1)?'发布图文':'发布视频'}}</status-title>
<view class="title-input">
<u-textarea v-model="form.content" placeholder="请输入内容..." count>
</u-textarea>
</view>
<!-- 上传图片 -->
<block v-if="form.type == 1">
<view style="padding: 0 10rpx;">
<uni-file-picker v-model="mediaList" ref="fileImage" :limit="9" :auto-upload="false"
fileMediatype="image" mode="grid" @select="handleSelect" @success="imageSuccess"
@delete="handleDelete">
</uni-file-picker>
</view>
</block>
<!-- 上传视频 -->
<block v-if="form.type == 2">
<view style="padding: 20rpx;">
<uni-file-picker ref="fileVideo" :limit="1" :auto-upload="false" fileMediatype="video" mode="grid"
@select="handleSelect" @success="videoSuccess" @delete="handleDelete"></uni-file-picker>
</view>
</block>
<u-line />
<view class="btn" @click="uploadMedia">发布</view>
</view>
</template>
<script>
import common from '@/mixins/common';
import {
imageCompress
} from "@/utils/utils.js"
import {
navigateTo,
message,
alert,
loading,
navigateBack
} from '@/utils/fun.js';
const app = getApp();
export default {
mixins: [common],
data() {
return {
form: {
type: 1,
content: '',
media: '',
},
mediaList: [],
};
},
onLoad(options) {
this.form.type = options.type;
},
methods: {
handleDelete(err) { // 删除
const num = this.mediaList.findIndex(v => v.url === err.tempFilePath);
this.mediaList.splice(num, 1);
},
handleSelect(err) { // 添加
this.mediaList.push(err.tempFiles[0])
},
async imageSuccess(e) {
let that = this
var promises = []
e.tempFiles.forEach(function(item, index) {
const promise = that.uploadFile(item, index)
promises.push(promise)
});
Promise.all(promises).then((result) => {
that.submit()
})
},
async videoSuccess(e) {
let that = this
var promises = []
e.tempFiles.forEach(function(item, index) {
const promise = that.uploadVideoFile(item, index)
promises.push(promise)
});
Promise.all(promises).then((result) => {
that.submit()
})
},
uploadMedia() {
if (!this.form.content) {
this.$u.toast('内容不能为空');
return;
}
loading.show('发布中')
var mediaList = this.mediaList
var allUploadOk = true
console.log(this.mediaList)
for (let file of mediaList) {
if (file.fileID == "" || file.fileID == undefined) {
allUploadOk = false
}
}
if (!allUploadOk) {
if (this.form.type == 1) {
this.$refs.fileImage.upload();
} else {
this.$refs.fileVideo.upload();
}
} else {
this.submit()
}
},
async uploadVideoFile(file, index) {
let that = this
return new Promise((resolve, reject) => {
uni.uploadFile({
url: app.globalData.baseUrl + '/app/uploadVideo?session=' + app.globalData
.token,
filePath: file.tempFilePath ? file.tempFilePath : file.path,
fileType: "video",
name: 'file',
formData: {
session: app.globalData.token,
},
success: (uploadFileRes) => {
let res = JSON.parse(uploadFileRes.data)
const currentIndex = this.mediaList.findIndex(v => v.url === file
.path);
if (res.data != null && res.code == '200') {
that.mediaList[currentIndex].url = file.path
that.mediaList[currentIndex].fileID = res.data.videoUrl
// if (currentIndex == 0) {
// that.form.media = res.data.videoUrl
// } else {
// that.form.media += (',' + res.data.videoUrl)
// }
resolve()
} else {
this.$refs.fileVideo.clearFiles(currentIndex)
this.mediaList.splice(currentIndex, 1);
reject()
loading.hide();
alert({
content: res.errorMsg || res.msg
})
}
},
fail: e => {
const currentIndex = this.mediaList.findIndex(v => v.url === file
.path);
this.$refs.fileVideo.clearFiles(currentIndex)
this.mediaList.splice(currentIndex, 1);
reject()
alert(e)
loading.hide();
}
});
})
},
async uploadFile(file, index) {
const currentIndex = this.mediaList.findIndex(v => v.path === file.path);
let compressFile = await imageCompress(file)
let that = this
that.mediaList[currentIndex].status = 'upload'
return new Promise((resolve, reject) => {
uni.uploadFile({
url: app.globalData.baseUrl + '/app/uploadImgNotCensor',
filePath: compressFile.tempFilePath ? compressFile.tempFilePath : compressFile
.path,
fileType: "image",
name: 'file',
formData: {
session: app.globalData.token
},
success: (uploadFileRes) => {
let res = JSON.parse(uploadFileRes.data)
if (res.data != null && res.code == '200') {
that.mediaList[currentIndex].url = file.path
that.mediaList[currentIndex].fileID = res.data.imgUrl
// if (currentIndex == 0) {
// that.form.media = res.data.imgUrl
// } else {
// that.form.media += (',' + res.data.imgUrl)
// }
resolve()
} else {
that.$refs.fileImage.clearFiles(currentIndex)
that.mediaList.splice(currentIndex, 1);
reject()
loading.hide();
alert({
content: res.errorMsg || res.msg
})
}
},
fail: e => {
that.mediaList.splice(currentIndex, 1);
that.$refs.fileImage.clearFiles(currentIndex)
reject()
alert(e)
loading.hide();
}
});
})
},
submit() {
this.form.media = ''
for (let item of this.mediaList) {
this.form.media += (',' + item.fileID)
}
this.post({
url: '/comment/add',
data: {
content: this.form.content,
media: this.form.media,
session: app.globalData.token,
mediaType: this.form.type
},
showLoading: true,
success: ({
data
}) => {
message.notify('发布成功')
navigateBack()
}
})
},
},
};
</script>
<style lang="scss" scoped>
.body {
background-color: white;
}
.title-input {
border-bottom: 1px solid #F5F5F5;
margin: 20rpx 0;
padding: 20rpx;
}
.upload-video {
width: 180rpx;
height: 180rpx;
margin-top: 30rpx;
}
.btn {
margin: 30rpx auto 80rpx auto;
width: 80%;
font-size: 28rpx;
color: #fff;
line-height: 70rpx;
height: 70rpx;
text-align: center;
border-radius: 10rpx;
background-color: #F8425A;
}
</style>
<template>
<view>
<status-title :showBack="true">视频动态</status-title>
<video class="video_" :enable-danmu="true" :danmu-btn="true" :autoplay="true" :enable-play-gesture="true"
:controls="false" :show-fullscreen-btn="false" :loop="true" :src="form.media">
<cover-image class="aiPk" style="width: 30px; height: 30px;" v-if="form.userLike==1"
@click="cancelCollection" src="../../static/moments/fav-1.png"></cover-image>
<cover-image class="aiPk" style="width: 30px; height: 30px;" v-else @click="addCollection"
src="../../static/moments/fav.png"></cover-image>
<cover-view v-if="form.userLike==1" class="modelStar1"
style="color: #FFFFFF;text-align: center;font-size: 24rpx;">
{{ form.likes }}
</cover-view>
<!-- <cover-image class="share" @click="" style="width: 30px; height: 30px;" src="/static/moments/share.png"> -->
</cover-image>
<cover-image class="modelPk " @click="down" style="width: 35px; height: 35px;"
src="/static/moments/down.png"></cover-image>
</video>
</view>
</template>
<script>
import common from '@/mixins/common';
const app = getApp();
export default {
mixins: [common],
data() {
return {
form: {
media: '',
userLike: 0,
likes: 0,
commentId: 0
},
};
},
filters: {
replace(str) {
str = str.replace(/\n/g, '');
if (str.length > 20) {
str = str.substring(0, 20) + '...';
}
return str;
}
},
computed: {
timestamp() {
return Date.parse(new Date()) / 1000;
}
},
onLoad(options) {
this.form.media = options.media ?? '';
this.form.userLike = options.userLike ?? 0;
this.form.likes = options.likes ?? 0;
this.form.commentId = options.commentId ?? '';
},
methods: {
down() {
let that = this;
uni.downloadFile({
url: that.form.media,
success: res => {
if (res.statusCode === 200) {
uni.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success: function() {
uni.hideLoading();
uni.showToast({
title: '保存成功',
icon: 'none'
});
},
fail: function() {
uni.hideLoading();
uni.showToast({
title: '保存失败,请稍后重试',
icon: 'none'
});
}
});
}
}
});
},
addCollection() {
this.post({
url: '/comment/like',
data: {
commentId: this.form.commentId,
type: 1,
session: app.globalData.token,
},
showLoading: false,
success: ({
data
}) => {
this.form.userLike = 1
if (this.form.likes == 0) {
this.form.likes += 1
}
}
})
},
cancelCollection() {
this.post({
url: '/comment/like',
data: {
commentId: this.form.commentId,
type: 0,
session: app.globalData.token,
},
showLoading: false,
success: ({
data
}) => {
this.form.userLike = 0
if (this.form.likes == 0) {
this.form.likes -= 1
}
}
})
}
},
onShareAppMessage(res) {
if (res.from === 'button') {
// 来自页面内分享按钮
console.log(res.target);
}
let imgURL;
if (this.postDetail.media.length > 0) {
imgURL = this.postDetail.media[0];
}
return {
title: this.postDetail.content,
path: '/pages/post/video-detail?id=' + this.postId
};
},
onShareTimeline() {
let imgURL = (imgURL = this.postDetail.media[0]);
return {
title: this.postDetail.content,
query: 'id=' + this.postId
};
}
};
</script>
<style>
page {
background-color: #000;
}
</style>
<style lang="scss" scoped>
.video_ {
width: 100%;
height: 100vh;
}
.aiPk {
position: absolute;
right: 0;
top: 360px;
width: 54px;
height: 54px;
padding: 2px 13px;
/* margin:0 14px; */
}
.modelStar {
position: absolute;
right: 0;
top: 420px;
width: 54px;
height: 54px;
padding: 3px 13px;
}
.modelStar1 {
position: absolute;
right: 0;
top: 390px;
width: 54px;
height: 54px;
padding: 3px 1px;
}
.share {
position: absolute;
right: 0;
top: 420px;
width: 54px;
height: 54px;
padding: 3px 13px;
}
.modelPk {
position: absolute;
right: 0;
top: 480px;
width: 54px;
height: 54px;
padding: 3px 13px;
}
</style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment