用户通过手机号验证码进行登录和注册 可以浏览动态列表中的所有动态 登录成功后用户可以发表自己的动态 也可以对自己认可欣赏的动态进行点赞和评论 也可以通过动态结识志同道合的朋友 进行聊天和探讨
当导航条在最顶部时此导航部分为透明,并且不显示朋友圈文字,当用户向下混动一定距离时,导航部分为灰色背景色显示文字,并且相机颜色为黑色,点击相机图标跳转到发布动态页面
onSuccess: function (ret) {
// 更换用户的背景图像
self.submit(ret)
}
async submit (obj) {
// 更新数据库中的背景图像
const res = await service.post('users/update', {
userId: this.$store.state.currentUser._id,
bgurl: obj.data.url
})
// 更新本地中的北背景图像
if (res.data.code === 0) {
this.$store.dispatch('setUser', {
...this.$store.state.currentUser,
bgurl: obj.data.url
})
}
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
<!-- 帖子中如果有多张图片 按照列表显示 图片的尺寸都一样 -->
<div class="img-content" v-if="data.picList.length>1">
<img v-for="imgInfo in data.picList"
:key="imgInfo.id"
:preview="data._id"
:src="imgInfo.url"
class="img-warp">
</div>
<!-- 如果帖子中只有一张图片 图片可以放大显示 要求狂傲不能超过200px -->
<div class="img-content-one" v-if="data.picList.length===1">
<img
:src="data.picList[0].url"
class="img-warp-one"
:preview="data._id"
:style="initImgSize(data.picList[0])">
</div>
获取当前手指的坐标 并触发bus中的showInput事件
addComment (e) {
// 获取当前点击的坐标
this.data.pageY = e.pageY
this.data.clientY = e.clientY
this.$bus.$emit('showInput', this.data)
}
当用户触发showInput事件后显示文本框
通过os进行检测用户的手机系统评论的文本框也是不同的
this.$bus.$on('showInput', (currentData) => {
if (this.$refs.inputBar) {
// 显示输入框
this.showInput = true
// 调用输入框组件的focusInput事件,以弹起键盘
this.$refs.inputBar.focusInput(currentData)
// this.$refs.inputWrap.style.top = currentData.pageY + 'px'
// 调整页面的位置
if (os.isIOS) {
this.$refs.inputWrap.style.top = currentData.pageY + 'px'
// 计算页面的滚动距离
setTimeout(() => {
const y = currentData.pageY - window.keyboradHeight
window.scroll(0, y)
}, 300)
}
}
})
在weui中的this指向并不是Vue实例所以在第一行中加入const self=this 让self常量指向我们的Vue实例
const self = this
weui.uploader('#uploader', {
url: service.baseURL + '/post/uploadimg',
auto: true,
type: 'file',
fileVal: 'image',
compress: {
width: 1600,
height: 1600,
quality: 0.8
},
onBeforeQueued: function (files) {
// `this` 是轮询到的文件, `files` 是所有文件
if (['image/jpg', 'image/jpeg', 'image/png', 'image/gif'].indexOf(this.type) < 0) {
weui.alert('请上传符合条件的图片')
return false // 阻止文件添加
}
if (this.size > 10 * 1024 * 1024) {
weui.alert('请上传不超过10M的图片')
return false
}
// 控制多元每次不能超过五张
if (files.length > self.totalUploadCount) {
weui.alert('最多只能上传' + self.totalUploadCount + '张图片,请重新选择')
return false
}
// 如果已经上传五张图片 作为不能继续上传
if (self.uploadCount + 1 > self.totalUploadCount) {
weui.alert('最多只能上传' + self.totalUploadCount + '张图片')
return false
}
self.uploadCount++
// return true; // 阻止默认行为,不插入预览图的框架
},
onBeforeSend: function (data, headers) {
const token = document.cookie.split('=')[1]
headers['wec-access-token'] = token
},
onProgress: function (procent) {
// console.log(this, procent)
// return true; // 阻止默认行为,不使用默认的进度显示
},
onSuccess: function (ret) {
ret.data.id = this.id
self.picList.push(ret.data)
},
onError: function (err) {
console.log('error:' + err)
// return true; // 阻止默认行为,不使用默认的失败态
}
})
preImg (e) {
const self = this
const url = e.target.getAttribute('style').split('"')[1]
var gallery = weui.gallery(url, {
onDelete: function () {
self.deleteImg(e.target, gallery)
}
})
}
deleteImg (target, gallery) {
const self = this
weui.confirm('确认删除图片吗', () => {
const id = target.getAttribute('data-id')
const index = self.picList.findIndex(item => {
return item.id === id
})
self.picList.splice(index, 1)
// 删除对应的DOM元素
target.remove()
self.uploadCount--
})
gallery.hide(function () {
console.log('`gallery`has been hidden')
})
}
onSuccess: async function (ret) {
// console.log(ret)
const res = await service.post('users/update', {
userId: self.$store.state.currentUser._id,
avatar: ret.data.url
})
if (res.data.code === 0) {
self.$store.dispatch('setUser', {
...self.$store.state.currentUser,
avatar: ret.data.url
})
weui.toast('上传成功', 2000)
}
}
weui.actionSheet([
{
label: '男',
onClick: async function () {
const res = await service.post('users/update', {
userId: self.$store.state.currentUser._id,
gender: '1'
})
if (res.data.code === 0) {
self.$store.dispatch('setUser', {
...self.$store.state.currentUser,
gender: '1'
})
weui.toast('修改成功', 1000)
}
}
},
{
label: '女',
onClick: async function () {
const res = await service.post('users/update', {
userId: self.$store.state.currentUser._id,
gender: '0'
})
if (res.data.code === 0) {
self.$store.dispatch('setUser', {
...self.$store.state.currentUser,
gender: '0'
})
weui.toast('修改成功', 1000)
}
}
}
], [
{
label: '取消',
onClick: function () {
console.log('取消')
}
}
])
我们采用animate实现页面之间的切换 animate样式官网点击查看 我们应该将样式应用到所有组件切换需要必经之路–App.vue
首先我要安装animate
$ npm install animate.css --save
在main.js中引用
import ‘animate.css’
需要将运用动画的元素使用标签包裹起来
<transition
:enter-active-class="transitionIN"
:leave-active-class="transitionOut"
>
<router-view/>
</transition>
里面的enter-active-class是为要切换来的(进场)设置动画
leave-active-class是为要切出(出场)设置动画,两属性值均为动态
考虑到不同的页面切换的动画应该不同 so我们采用侦听器来检测路由的变化进而对个别的页面做出个性动画
// 侦听器:侦听路由的变化进而应用不同的转场动画
watch: {
$route (to, from) {
if (to.name === 'Publish') {
this.transitionIN = 'animate__animated animate__slideInUp'
this.transitionOut = ''
} else if (from.name === 'Publish') {
this.transitionIN = ''
this.transitionOut = 'animate__animated animate__slideOutDown'
} else {
this.transitionIN = 'animate__animated animate__slideInLeft'
this.transitionOut = 'animate__animated animate__slideOutLeft'
}
}
}