Commit 735870a9 authored by liwei's avatar liwei

修改了动态页面

parent 6f616850
...@@ -20,10 +20,7 @@ ...@@ -20,10 +20,7 @@
</view> </view>
<!-- </template> --> <!-- </template> -->
<!-- <empty v-if="firstLoaded&&!dataList.length"></empty> --> <!-- <empty v-if="firstLoaded&&!dataList.length"></empty> -->
</z-paging> </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> </view>
</template> </template>
...@@ -31,12 +28,10 @@ ...@@ -31,12 +28,10 @@
import ItemVue from './Item.vue' import ItemVue from './Item.vue'
import empty from '@/components/empty.vue' import empty from '@/components/empty.vue'
import login from '../../components/login/login.vue' import login from '../../components/login/login.vue'
import ELM from '../../components/elm-toast/index.vue';
export default { export default {
components: { components: {
ItemVue, ItemVue,
empty, empty,
ELM,
login login
}, },
data() { data() {
...@@ -47,10 +42,6 @@ ...@@ -47,10 +42,6 @@
firstLoaded: false, firstLoaded: false,
// 是否滚动到当前页 // 是否滚动到当前页
isCurrentPage: false, isCurrentPage: false,
isLoginPop: false,
chilkLog:false,
tipMsg: '',
isConfirm: false
} }
}, },
props: { props: {
...@@ -78,7 +69,7 @@ ...@@ -78,7 +69,7 @@
watch: { watch: {
currentIndex: { currentIndex: {
handler(newVal) { handler(newVal) {
console.log("切换到了第:" + newVal + " pop:" + this.isLoginPop) console.log("切换到了第:" + newVal)
if (newVal === this.tabIndex) { if (newVal === this.tabIndex) {
// 懒加载,当滑动到当前的item时,才去加载 // 懒加载,当滑动到当前的item时,才去加载
if (!this.firstLoaded) { if (!this.firstLoaded) {
...@@ -93,10 +84,7 @@ ...@@ -93,10 +84,7 @@
} }
if (newVal == 0 || newVal == 2) { if (newVal == 0 || newVal == 2) {
console.log("进入判断第" + newVal + "个") console.log("进入判断第" + newVal + "个")
if (uni.getStorageSync('info') == '') {
this.isLoginPop = true;
}
} }
}, },
immediate: true immediate: true
...@@ -125,49 +113,42 @@ ...@@ -125,49 +113,42 @@
this.dataList.splice(idx, 1) this.dataList.splice(idx, 1)
} }
else{ else{
this.tipMsg = res.data.msg;
this.$refs.elm.showDialog();
} }
}) })
}, },
// 点赞 // 点赞
praise(value) { 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() { reload() {
...@@ -180,188 +161,86 @@ ...@@ -180,188 +161,86 @@
// 组件加载时会自动触发此方法,因此默认页面加载时会自动触发,无需手动调用 // 组件加载时会自动触发此方法,因此默认页面加载时会自动触发,无需手动调用
// 这里的pageNo和pageSize会自动计算好,直接传给服务器即可 // 这里的pageNo和pageSize会自动计算好,直接传给服务器即可
// 模拟请求服务器获取分页数据,请替换成自己的网络请求 // 模拟请求服务器获取分页数据,请替换成自己的网络请求
const params = { this.dataList = [
pageIndex: pageNo, {
pageSize: pageSize, createTime:'2024-12-28 15:02:01',
type: this.tabIndex headPortrait:'11111',//头像
} nickName:'不爱吃辣的小王',//nickName
if (this.tabIndex == 0) { gender:'MALE',//性别
params.tabType = "FOLLOW" information:'02·重庆市·硕士·互联网',//个人信息
} else if (this.tabIndex == 1) { content:'昨天的快乐留在今天发,那就是100%',//动态内容
params.tabType = "RECOMMEND" time:'2024-11-11 15:02:01',//发布动态的时间
} else { commentCount:'10',//评论数
params.tabType = "CITY" likeCount:'11',//点赞数
} },
this.$myRequest({ ]
url: `/nostalgia/article/page`, // const params = {
data: params, // pageIndex: pageNo,
withToken: true, // pageSize: pageSize,
method: 'GET', // type: this.tabIndex
}).then(res => { // }
if (res.data.code == 200) { // if (this.tabIndex == 0) {
let arr = res.data.data.rows.map(item => { // params.tabType = "FOLLOW"
return { // } else if (this.tabIndex == 1) {
...item, // params.tabType = "RECOMMEND"
isDel: item.userId == this.userInfo != null ? this.userInfo.id : 0 // } else {
} // params.tabType = "CITY"
}) // }
this.$refs.paging.complete(arr); // this.$myRequest({
setTimeout(() => { // url: `/nostalgia/article/page`,
this.firstLoaded = true; // data: params,
}, 100) // withToken: true,
} else if (res.data.code == 10006) { // method: 'GET',
let rows = []; // }).then(res => {
let arr = rows.map(item => { // if (res.data.code == 200) {
return { // let arr = res.data.data.rows.map(item => {
...item, // return {
isDel: item.userId == this.userInfo != null ? this.userInfo.id : 0 // ...item,
} // isDel: item.userId == this.userInfo != null ? this.userInfo.id : 0
}) // }
this.$refs.paging.complete(arr); // })
setTimeout(() => { // this.$refs.paging.complete(arr);
this.firstLoaded = true; // setTimeout(() => {
}, 100) // this.firstLoaded = true;
// }, 100)
} else { // } else if (res.data.code == 10006) {
let rows = []; // let rows = [];
let arr = rows.map(item => { // let arr = rows.map(item => {
return { // return {
...item, // ...item,
isDel: item.userId == this.userInfo != null ? this.userInfo.id : 0 // isDel: item.userId == this.userInfo != null ? this.userInfo.id : 0
} // }
}) // })
this.$refs.paging.complete(arr); // this.$refs.paging.complete(arr);
setTimeout(() => { // setTimeout(() => {
this.firstLoaded = true; // this.firstLoaded = true;
}, 100) // }, 100)
console.log("请求失败") //
} // } else {
}).catch(res => { // let rows = [];
// 如果请求失败写this.$refs.paging.complete(false); // let arr = rows.map(item => {
// 注意,每次都需要在catch中写这句话很麻烦,z-paging提供了方案可以全局统一处理 // return {
// 在底层的网络请求抛出异常时,写uni.$emit('z-paging-error-emit');即可 // ...item,
console.log("请求接口失败了") // isDel: item.userId == this.userInfo != null ? this.userInfo.id : 0
this.$refs.paging.complete(false); // }
}) // })
// 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) { itemClick(item) {
console.log('点击了-----', item.title); 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> </script>
...@@ -369,6 +248,5 @@ ...@@ -369,6 +248,5 @@
<style scoped> <style scoped>
.content { .content {
height: 100%; height: 100%;
/* padding: 0 32rpx 30rpx 32rpx; */
} }
</style> </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