Commit 735870a9 authored by liwei's avatar liwei

修改了动态页面

parent 6f616850
......@@ -20,10 +20,7 @@
</view>
<!-- </template> -->
<!-- <empty v-if="firstLoaded&&!dataList.length"></empty> -->
</z-paging>
<ELM ref="elm" :msg="tipMsg" :isConfirm="isConfirm" @confirm="confirm"></ELM>
<login @change="getUserInfo" :isLoginPop="(isLoginPop&&tabIndex!=1)||chilkLog" class="my-select"></login>
</view>
</template>
......@@ -31,12 +28,10 @@
import ItemVue from './Item.vue'
import empty from '@/components/empty.vue'
import login from '../../components/login/login.vue'
import ELM from '../../components/elm-toast/index.vue';
export default {
components: {
ItemVue,
empty,
ELM,
login
},
data() {
......@@ -47,10 +42,6 @@
firstLoaded: false,
// 是否滚动到当前页
isCurrentPage: false,
isLoginPop: false,
chilkLog:false,
tipMsg: '',
isConfirm: false
}
},
props: {
......@@ -78,7 +69,7 @@
watch: {
currentIndex: {
handler(newVal) {
console.log("切换到了第:" + newVal + " pop:" + this.isLoginPop)
console.log("切换到了第:" + newVal)
if (newVal === this.tabIndex) {
// 懒加载,当滑动到当前的item时,才去加载
if (!this.firstLoaded) {
......@@ -93,10 +84,7 @@
}
if (newVal == 0 || newVal == 2) {
console.log("进入判断第" + newVal + "个")
if (uni.getStorageSync('info') == '') {
this.isLoginPop = true;
}
}
},
immediate: true
......@@ -125,49 +113,42 @@
this.dataList.splice(idx, 1)
}
else{
this.tipMsg = res.data.msg;
this.$refs.elm.showDialog();
}
})
},
// 点赞
praise(value) {
let obj = {
...value,
}
let url = ''
if (obj.isLike) {
url = 'nostalgia/article/cancel/praise'
obj.likeCount -= 1
} else {
url = 'nostalgia/article/praise'
obj.likeCount += 1
}
this.$myRequest({
url,
data: {
id: value.id,
praiseType: "ARTICLE"
},
withToken: true,
method: 'PUT',
}).then(res => {
if (res.data.code == "200") {
obj.isLike = !value.isLike
let idx = this.dataList.findIndex(item => item.id == obj.id)
this.dataList.splice(idx, 1, obj)
} else if(res.data.code == "10006"){
console.log("报错了:"+res.data.code)
this.chilkLog=true;
}
else{
this.tipMsg = res.data.msg;
this.$refs.elm.showDialog();
}
})
// let obj = {
// ...value,
// }
// let url = ''
// if (obj.isLike) {
// url = 'nostalgia/article/cancel/praise'
// obj.likeCount -= 1
// } else {
// url = 'nostalgia/article/praise'
// obj.likeCount += 1
// }
// this.$myRequest({
// url,
// data: {
// id: value.id,
// praiseType: "ARTICLE"
// },
// withToken: true,
// method: 'PUT',
// }).then(res => {
// if (res.data.code == "200") {
// obj.isLike = !value.isLike
// let idx = this.dataList.findIndex(item => item.id == obj.id)
// this.dataList.splice(idx, 1, obj)
// } else if(res.data.code == "10006"){
// console.log("报错了:"+res.data.code)
// }
// })
},
// 接收父组件传过来的刷新列表要求
reload() {
......@@ -180,188 +161,86 @@
// 组件加载时会自动触发此方法,因此默认页面加载时会自动触发,无需手动调用
// 这里的pageNo和pageSize会自动计算好,直接传给服务器即可
// 模拟请求服务器获取分页数据,请替换成自己的网络请求
const params = {
pageIndex: pageNo,
pageSize: pageSize,
type: this.tabIndex
}
if (this.tabIndex == 0) {
params.tabType = "FOLLOW"
} else if (this.tabIndex == 1) {
params.tabType = "RECOMMEND"
} else {
params.tabType = "CITY"
}
this.$myRequest({
url: `/nostalgia/article/page`,
data: params,
withToken: true,
method: 'GET',
}).then(res => {
if (res.data.code == 200) {
let arr = res.data.data.rows.map(item => {
return {
...item,
isDel: item.userId == this.userInfo != null ? this.userInfo.id : 0
}
})
this.$refs.paging.complete(arr);
setTimeout(() => {
this.firstLoaded = true;
}, 100)
} else if (res.data.code == 10006) {
let rows = [];
let arr = rows.map(item => {
return {
...item,
isDel: item.userId == this.userInfo != null ? this.userInfo.id : 0
}
})
this.$refs.paging.complete(arr);
setTimeout(() => {
this.firstLoaded = true;
}, 100)
} else {
let rows = [];
let arr = rows.map(item => {
return {
...item,
isDel: item.userId == this.userInfo != null ? this.userInfo.id : 0
}
})
this.$refs.paging.complete(arr);
setTimeout(() => {
this.firstLoaded = true;
}, 100)
console.log("请求失败")
}
}).catch(res => {
// 如果请求失败写this.$refs.paging.complete(false);
// 注意,每次都需要在catch中写这句话很麻烦,z-paging提供了方案可以全局统一处理
// 在底层的网络请求抛出异常时,写uni.$emit('z-paging-error-emit');即可
console.log("请求接口失败了")
this.$refs.paging.complete(false);
})
this.dataList = [
{
createTime:'2024-12-28 15:02:01',
headPortrait:'11111',//头像
nickName:'不爱吃辣的小王',//nickName
gender:'MALE',//性别
information:'02·重庆市·硕士·互联网',//个人信息
content:'昨天的快乐留在今天发,那就是100%',//动态内容
time:'2024-11-11 15:02:01',//发布动态的时间
commentCount:'10',//评论数
likeCount:'11',//点赞数
},
]
// const params = {
// pageIndex: pageNo,
// pageSize: pageSize,
// type: this.tabIndex
// }
// if (this.tabIndex == 0) {
// params.tabType = "FOLLOW"
// } else if (this.tabIndex == 1) {
// params.tabType = "RECOMMEND"
// } else {
// params.tabType = "CITY"
// }
// this.$myRequest({
// url: `/nostalgia/article/page`,
// data: params,
// withToken: true,
// method: 'GET',
// }).then(res => {
// if (res.data.code == 200) {
// let arr = res.data.data.rows.map(item => {
// return {
// ...item,
// isDel: item.userId == this.userInfo != null ? this.userInfo.id : 0
// }
// })
// this.$refs.paging.complete(arr);
// setTimeout(() => {
// this.firstLoaded = true;
// }, 100)
// } else if (res.data.code == 10006) {
// let rows = [];
// let arr = rows.map(item => {
// return {
// ...item,
// isDel: item.userId == this.userInfo != null ? this.userInfo.id : 0
// }
// })
// this.$refs.paging.complete(arr);
// setTimeout(() => {
// this.firstLoaded = true;
// }, 100)
//
// } else {
// let rows = [];
// let arr = rows.map(item => {
// return {
// ...item,
// isDel: item.userId == this.userInfo != null ? this.userInfo.id : 0
// }
// })
// this.$refs.paging.complete(arr);
// setTimeout(() => {
// this.firstLoaded = true;
// }, 100)
// console.log("请求失败")
// }
// }).catch(res => {
// // 如果请求失败写this.$refs.paging.complete(false);
// // 注意,每次都需要在catch中写这句话很麻烦,z-paging提供了方案可以全局统一处理
// // 在底层的网络请求抛出异常时,写uni.$emit('z-paging-error-emit');即可
// console.log("请求接口失败了")
// this.$refs.paging.complete(false);
// })
},
itemClick(item) {
console.log('点击了-----', item.title);
},
getUserInfo(e) {
if (e == 0) {
this.isLoginPop = false;
this.chilkLog=false;
return;
}
// #ifdef MP-WEIXIN
try {
wx.getUserProfile({
desc: '用于完善会员资料',
success: resinfo => {
wx.login({
success: res => {
if (res.code) {
console.log(res.code, resinfo);
this.setCode(res.code, resinfo);
} else {}
},
fail: err => {}
});
},
fail: errinfo => {
this.setCode(this.generateRandomString(10), 'null');
}
});
} catch {
wx.getUserInfo({
success: resinfo => {
wx.login({
success: res => {
if (res.code) {
console.log(res.code, resinfo);
this.setCode(res.code, resinfo);
} else {}
},
fail: err => {}
});
},
fail: errinfo => {}
});
}
// #endif
// #ifndef MP-WEIXIN
this.setCode("ip", 'null');
// #endif
},
async setCode(code, resinfo) {
const res = await this.$myRequest({
url: 'token/wxAppletLogin',
data: {
code: code
},
method: 'POST'
});
console.log(res, 'delshoucang');
var obj = {
code: code,
state: res.data.code,
nickName: resinfo != 'null' ? resinfo.userInfo.nickName : "匿名用户"
};
uni.setStorageSync('verification', obj);
if (res.data.code == 200) {
this.isLoginPop = false;
this.isConfirm = true;
this.tipMsg = "登录成功";
this.$refs.elm.showDialog();
var info = {
birthday: res.data.data.info.birthday,
city: res.data.data.info.city,
gender: res.data.data.info.gender,
headPortrait: res.data.data.info.headPortrait,
id: res.data.data.info.id,
nickName: res.data.data.info.nickName
};
uni.setStorageSync('info', info);
uni.setStorageSync('token', res.data.data.token);
} else if (res.data.code == 11002) {
this.isLoginPop = false;
uni.reLaunch({
url: '/pagesintroduction/selfIntroduction?code=' + code
});
} else {
this.tipMsg = res.data.msg;
this.$refs.elm.showDialog();
}
},
confirm() {
this.isConfirm = false;
},
generateRandomString(length) {
let result = uni.getStorageSync('touristopenid');
if (result != null&&result!="") {
return result;
}else{
result='';
}
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; // 包含大小写字母和数字的所有字符集合
for (let i = 0; i < length; i++) {
const randomIndex = Math.floor(Math.random() * characters.length);
result += characters[randomIndex];
}
var now = new Date();
var year = now.getFullYear(); // 年份
var month = (now.getMonth() + 1).toString().padStart(2, '0'); // 月份(注意要加上1)
var day = now.getDate().toString().padStart(2, '0'); // 天数
var hours = now.getHours().toString().padStart(2, '0'); // 小时
var minutes = now.getMinutes().toString().padStart(2, '0'); // 分钟
var seconds = now.getSeconds().toString().padStart(2, '0'); // 秒数
result = "touristopenid" + result + (+year + month + day + hours + minutes + seconds);
uni.setStorageSync('touristopenid', result);
return result;
}
}
}
</script>
......@@ -369,6 +248,5 @@
<style scoped>
.content {
height: 100%;
/* padding: 0 32rpx 30rpx 32rpx; */
}
</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