index.vue 27.9 KB
Newer Older
xhw committed
1 2 3 4 5 6 7 8 9 10 11
<template>
    <view class="wrapper">
        <!-- 获取用户信息 -->
        <view v-if="showUserInfo" class="ttt">
            <button class="avatar-wrapper" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
                <image class="avatar" :src="avatarUrl"></image>
            </button> 
            <view class="tipUserHeader">设置头像</view>
            <input class="weui-input" v-model="userName" placeholder="请输入昵称"/>
            <button type="primary" :disabled="disabledSubmit" @click="handleSubmit" class="submit">提交</button>
        </view>
xhw committed
12 13
        <button @click="handleUserDestory"> 用户注销  </button>
        <view class="shadow"></view>
xhw committed
14 15 16 17

        <view class="section" >
            <view class="shadowBoard" :style="{backgroundImage:'url('+ photo[i] +')'}"></view>
            <view class="swiper">
18 19 20 21 22 23 24 25 26 27 28 29 30
                <image
                    @click="preImage"
                    class="scaleToFill"
                    src="../../static/photo/left.png"
                    mode="scaleToFill"
                />
                <image
                    @click="nextImage"
                    class="scaleToFill2"
                    src="../../static/photo/left.png"
                    mode="scaleToFill"
                />
                <z-swiper ref="zSwiper" v-model="list" @slideChange="onSlideChange" :options="options" class="swiper">
xhw committed
31
                    <z-swiper-item :custom-style="slideCustomStyle" v-for="(item,index) in list" :key="index">
32 33
                        <button class="btn" @click="NavTo(item)">
                            <image class="image" :src="'https://admin.mindepoch.com:8089/worlds/' + item.name + '.png'" mode="aspectFill"></image>
xhw committed
34 35
                            <view class="CardContent">
                                <view class="card">
36
                                    <view class="header1">{{item.name}}</view>
xhw committed
37
                                    <view class="header2">
38
                                        <view class="sdsd">{{item.worldHeader}}</view>
xhw committed
39
                                        <view class="distence"></view>
40
                                        <view class="detail">{{item.description}}</view>
xhw committed
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
                                    </view>
                                </view>
                            </view>
                        </button>
                    </z-swiper-item>
                </z-swiper>
            </view>
        </view>
    </view>
</template>

<script>
export default {
    data() {
        return {
            err:null,
            disabledSubmit:false,
            id:274,
            showUserInfo:false,
xhw committed
60
            userName:'卿羽',
xhw committed
61 62 63 64 65 66
            code:'',
            clickNoArgee:false,
            clickArgee:false,
            isBindPhone:false,
            needDialog:true,
            nickName:'',
67 68
            // avatarUrl:'/static/photo/default.jpg',
            avatarUrl:'https://admin.mindepoch.com:8089/worlds/default.jpg',
xhw committed
69 70 71 72 73 74 75 76
            OpenId:'',
            i:0,
            photo:[
                'https://admin.mindepoch.com:8089/worlds/情圣日记.png',
                'https://admin.mindepoch.com:8089/worlds/荒村公寓.png',
                'https://admin.mindepoch.com:8089/worlds/舌战群儒.png'
            ],
            list: [
77 78 79
                // {image:'https://admin.mindepoch.com:8089/worlds/情圣日记.png',title:'情圣日记',content1:'-Love&Entropy',content2:'你还...记得我吗?'},
                // {image:'https://admin.mindepoch.com:8089/worlds/荒村公寓.png',title:'荒村公寓',content1:'-规则怪谈',content2:'一觉醒来,身处陌生的公寓,奇怪的规则,神秘的怪谈,我该如何逃生'},
                // {image:'https://admin.mindepoch.com:8089/worlds/舌战群儒.png',title:'荒村公寓',content1:'-规则怪谈',content2:'一觉醒来,身处陌生的公寓,奇怪的规则,神秘的怪谈,我该如何逃生'},
xhw committed
80 81
            ],
            options:{
82 83
                effect: 'cards',
                loop : true,
xhw committed
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
            },
            slideCustomStyle: {
                display: 'flex',
                alignItems: 'center',
                justifyContent: 'center',
                borderRadius: '36rpx'
            }
        }
    },
    mounted() {
        //用户验证用户是否登陆过
        // console.log(this)
        var that = this
        wx.login({
            success(res) {
                if (res.code) {
                    // uni.setStorageSync('code', res.code)
                    that.code = res.code
xhw committed
102 103 104 105 106
                    console.log('code:',that.code)
                    // uni.showModal({
                    //     title: 'wx.login:登录ing!',
                    //     content: 'that.code:'+that.code + ''
                    // });
xhw committed
107 108 109 110 111 112 113 114 115
                    // 将 res.code 发送至后台服务器进行处理
                    uni.request({
                        url: 'https://admin.mindepoch.com:8089/wechat/CheckWxUserIsRegisterAndBindPhone',
                        method: 'POST',
                        header: {
                            'Content-Type': 'application/x-www-form-urlencoded'
                        },
                        data: { code: res.code },
                        success: function(res) {
xhw committed
116 117 118 119 120
                            console.log('res:',res)
                            // uni.showModal({
                            //     title: 'wx.login:登录成功!'+JSON.stringify(res),
                            //     content: res.data.toString()
                            // });
xhw committed
121 122
                            that.isBindPhone = res.data.isBindPhone
                            that.wxUid = res.data.wxUid
123
                            
xhw committed
124 125 126 127
                            if(res.data.message==="微信用户已注册,模拟登录成功!"){
                                uni.setStorageSync('wxUid', res.data.wxUid); //保存用户id
                                uni.setStorageSync('userName', res.data.userName)
                                uni.setStorageSync('session_token', res.cookies[0].split(';')[0]) //保存cookie值
128
                                that.init()
xhw committed
129 130 131
                            }else{
                                if(res.data.code===1){
                                    //用户已注册
132
                                    that.init()
xhw committed
133 134 135 136 137 138
                                }else{
                                    that.showUserInfo = true
                                }
                            }
                        },
                        fail: function(err) {
xhw committed
139 140 141 142 143
                            console.log('err:',err)
                            // uni.showModal({
                            //     title: 'wx.login:登录失败!',
                            //     content: JSON.stringify(err)
                            // });
xhw committed
144 145 146 147 148 149 150
                        }
                    })
                } else {
                    console.error('登录失败!' + res.errMsg);
                }
            }
        })
151
        
xhw committed
152 153 154
    },
    onload() {},
    methods: {
155 156 157 158 159 160 161 162 163 164 165 166
        init(){
            uni.request({
                url: 'https://admin.mindepoch.com:8089/QueryWorldsByLikeName',
                header: {
                    'Cookie': `${uni.getStorageSync('session_token')}`,
                    'Content-Type': 'application/x-www-form-urlencoded'
                },
                method: 'post',
                data:{
                    worldName: ''
                }
            }).then(result => {
xhw committed
167 168 169 170 171
                console.log('init:',result[1].data)
                // uni.showModal({
                //     title: 'init:',
                //     content: result[1].data.worldInfoAndAsset.toString()
                // });
172 173 174
                if(result[1].data.code===1){
                    if(result[1].data.worldInfoAndAsset.length>0){
                        this.list = result[1].data.worldInfoAndAsset
xhw committed
175
                        // this.list = [result[1].data.worldInfoAndAsset[1]]
176 177 178 179
                    }
                }
            }).catch(err=> {
                console.log(222,err)
xhw committed
180 181 182 183
                // uni.showModal({
                //     title: 'init_error:',
                //     content: 'error'
                // });
184 185 186 187 188 189 190 191 192 193
            });
        },
        preImage(){
            // console.log('pre')
            this.$refs.zSwiper.swiper.slidePrev();
        },
        nextImage(){
            // console.log('next')
            this.$refs.zSwiper.swiper.slideNext();
        },
xhw committed
194 195 196
        //获取到用户昵称  以及用户头像
        handleSubmit(){
            var that = this
xhw committed
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
            //1.昵称输入不可为空
            if(this.userName.trim()==""){
                uni.showToast({
                    title: '昵称不可为空',
                    icon: 'none'
                })
                return
            }
            //2.不上传头像需要下载 上传头像不需要下载
            if(this.avatarUrl=="https://admin.mindepoch.com:8089/worlds/default.jpg"){
                uni.downloadFile({
                    url: that.avatarUrl,
                    success: downloadRes => {
                        if (downloadRes.statusCode === 200) {
                            // 图片下载成功后获取临时文件路径
                            const tempFilePath = downloadRes.tempFilePath;
                            wx.login({
                                success(res) {
                                    if(!res.code) {
                                        return
                                    }
                                    uni.uploadFile({
                                        url: 'https://admin.mindepoch.com:8089/wechat/AppletWeChatRegisterOrLogin',
                                        method: 'POST',
                                        filePath:tempFilePath,
                                        name: 'avatar',
                                        formData: {
                                            code: res.code,
                                            username: that.userName
                                        },
                                        success: uploadRes => {
                                            console.log('上传成功uploadRes', uploadRes);
                                            // console.log(JSON.parse(uploadRes.data))
                                            const data = JSON.parse(uploadRes.data)
                                            if(data.code===1){
                                                uni.showToast({
                                                    title: '头像上传成功!',
                                                    icon: 'none'
                                                });
                                                uni.setStorageSync('userName', that.userName);
                                                uni.setStorageSync('session_token', uploadRes.cookies[0].split(';')[0]); //保存cookie值
                                                uni.setStorageSync('wxUid', data.wxUid); //保存用户id
                                                uni.setStorageSync('openId', data.openId); //保存用户id
                                                that.showUserInfo = false //隐藏用户填写的表单
                                                that.init()
                                            }else{
                                                //失败
                                                uni.showModal({
                                                    title: '温馨提示', // 弹窗的标题
                                                    content: '好像出了点问题呢,再试试呢!', // 弹窗的文本内容
                                                    showCancel: true, // 是否显示取消按钮,默认为 true
                                                    cancelText: '取消', // 取消按钮的文字,默认为"取消"
                                                    cancelColor: '#000000', // 取消按钮的文字颜色
                                                    confirmText: '确定', // 确定按钮的文字,默认为"确定"
                                                    confirmColor: '#576B95', // 确定按钮的文字颜色
                                                    success: function (res) {
                                                        if (res.confirm) {
                                                            console.log('用户点击确定');
                                                        } else if (res.cancel) {
                                                            console.log('用户点击取消');
                                                        }
                                                    },
                                                    fail: function (err) {
                                                        console.log('API 调用失败: ', err);
                                                    }
                                                });
                                                that.disabledSubmit = false
                                            }
                                        },
                                        fail: uploadErr => {
                                            console.error('上传失败', uploadErr);
                                            uni.showModal({
                                                title: '失败', // 弹窗的标题
                                                content: '创建失败!', // 弹窗的文本内容 JSON.parse(uploadErr.errMsg)
                                                showCancel: true, // 是否显示取消按钮,默认为 true
                                                cancelText: '取消', // 取消按钮的文字,默认为"取消"
                                                cancelColor: '#000000', // 取消按钮的文字颜色
                                                confirmText: '确定', // 确定按钮的文字,默认为"确定"
                                                confirmColor: '#576B95', // 确定按钮的文字颜色
                                                success: function (res) {
                                                    if (res.confirm) {
                                                        console.log('用户点击确定');
                                                    } else if (res.cancel) {
                                                        console.log('用户点击取消');
                                                    }
                                                },
                                                fail: function (err) {
                                                    console.log('API 调用失败: ', err);
                                                }
                                            });
                                            
                                        }
                                    })                                    
                                },
                                fail(err){
                                    console.log(err)
                                    uni.showToast({
                                        title: err.toString(),
                                        icon: 'none'
                                    })
                                }
298
                            })
xhw committed
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
                        }
                    },
                    fail: downloadErr => {
                        console.error('下载图片失败', downloadErr)
                        // uni.showModal({
                        //     title: '弹窗标题', // 弹窗的标题
                        //     content: JSON.stringify(downloadErr), // 弹窗的文本内容
                        //     showCancel: true, // 是否显示取消按钮,默认为 true
                        //     cancelText: '取消', // 取消按钮的文字,默认为"取消"
                        //     cancelColor: '#000000', // 取消按钮的文字颜色
                        //     confirmText: '确定', // 确定按钮的文字,默认为"确定"
                        //     confirmColor: '#576B95', // 确定按钮的文字颜色
                        //     success: function (res) {
                        //         if (res.confirm) {
                        //             console.log('用户点击确定');
                        //         } else if (res.cancel) {
                        //             console.log('用户点击取消');
                        //         }
                        //     },
                        //     fail: function (err) {
                        //         console.log('API 调用失败: ', err);
                        //     }
                        // });
                    }
                });
            }else{
                this.disabledSubmit = true
                wx.login({
                    success(res) {
                        if(!res.code) {
                            return
                        }
                        uni.uploadFile({
                            url: 'https://admin.mindepoch.com:8089/wechat/AppletWeChatRegisterOrLogin',
                            method: 'POST',
                            filePath:that.avatarUrl,
                            name: 'avatar',
                            formData: {
                                code: res.code,
                                username: that.userName
                            },
                            success: uploadRes => {
341
                                uni.showToast({
xhw committed
342
                                    title: 'AppletWeChatRegisterOrLogin',
343
                                    icon: 'none'
xhw committed
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
                                })
                                console.log('上传成功uploadRes', uploadRes);
                                console.log(JSON.parse(uploadRes.data))
                                const data = JSON.parse(uploadRes.data)
                                if(data.code===1){
                                    uni.showToast({
                                        title: '成功!',
                                        icon: 'none'
                                    });
                                    uni.setStorageSync('userName', that.userName);
                                    uni.setStorageSync('session_token', uploadRes.cookies[0].split(';')[0]); //保存cookie值
                                    uni.setStorageSync('wxUid', data.wxUid); //保存用户id
                                    uni.setStorageSync('openId', data.openId); //保存用户id
                                    that.showUserInfo = false //隐藏用户填写的表单
                                    that.init()
                                }else{
                                    //失败
                                    uni.showModal({
                                        title: '温馨提示', // 弹窗的标题
                                        content: '好像出了点问题呢,再试试呢!', // 弹窗的文本内容
                                        showCancel: true, // 是否显示取消按钮,默认为 true
                                        cancelText: '取消', // 取消按钮的文字,默认为"取消"
                                        cancelColor: '#000000', // 取消按钮的文字颜色
                                        confirmText: '确定', // 确定按钮的文字,默认为"确定"
                                        confirmColor: '#576B95', // 确定按钮的文字颜色
                                        success: function (res) {
                                            if (res.confirm) {
                                                console.log('用户点击确定');
                                            } else if (res.cancel) {
                                                console.log('用户点击取消');
                                            }
                                        },
                                        fail: function (err) {
                                            console.log('API 调用失败: ', err);
                                        }
                                    });
                                    that.disabledSubmit = false
                                }
                            },
                            fail: uploadErr => {
                                console.error('上传失败', uploadErr);
                                uni.showModal({
                                    title: '失败', // 弹窗的标题
                                    content: '创建失败!', // 弹窗的文本内容 JSON.parse(uploadErr.errMsg)
                                    showCancel: true, // 是否显示取消按钮,默认为 true
                                    cancelText: '取消', // 取消按钮的文字,默认为"取消"
                                    cancelColor: '#000000', // 取消按钮的文字颜色
                                    confirmText: '确定', // 确定按钮的文字,默认为"确定"
                                    confirmColor: '#576B95', // 确定按钮的文字颜色
                                    success: function (res) {
                                        if (res.confirm) {
                                            console.log('用户点击确定');
                                        } else if (res.cancel) {
                                            console.log('用户点击取消');
                                        }
                                    },
                                    fail: function (err) {
                                        console.log('API 调用失败: ', err);
                                    }
403
                                });
xhw committed
404
                                
xhw committed
405
                            }
xhw committed
406 407 408 409 410 411 412 413 414 415 416
                        })
                    },
                    fail(err){
                        console.log(err)
                        uni.showToast({
                            title: err.toString(),
                            icon: 'none'
                        })
                    }
                })
            }
xhw committed
417 418
        },
        onChooseAvatar(e) {
419
            console.log('e',e)
xhw committed
420 421
            const { avatarUrl } = e.detail 
            this.avatarUrl = avatarUrl
xhw committed
422
            console.log('this.avatarUrl',this.avatarUrl)
xhw committed
423 424
        },

425 426 427 428
        NavTo(data) {
            uni.navigateTo({
                url: `/pages/index/index?params=${JSON.stringify(data)}`
            });
xhw committed
429

430 431 432 433 434 435 436 437
            // console.log(title)
            // if(title==='情圣日记'){
            // }else{
            //     uni.showToast({
            //         title: '敬请期待',
            //         icon: 'none'
            //     });
            // }
xhw committed
438 439 440
        },
        onSlideChange(swiper,index) {
            console.log(swiper,index)
441 442 443 444 445 446 447 448
            // const len = this.photo.length + 1
            if(this.photo.length+1==index){
                this.i = 0
            }else if(index==0){
                this.i = this.photo.length-1
            }else{
                this.i = index-1
            }
xhw committed
449
            // 你可以在这里获取当前的swiper索引
450
            // const currentIndex = swiper.activeIndex;
xhw committed
451 452 453
            // 执行你想要的操作,比如更新页面标题
            // uni.setNavigationBarTitle('当前页: ' + (currentIndex + 1));
        },
454

xhw committed
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505
        getAuth() {
            wx.getUserProfile({
                withCredentials: true,
                lang: 'zh_CN',
                desc:'提升用户体验,减少用户操作',
                success: function (userRes) {
                    console.log('userRes',userRes)
                    // var userInfo = userRes.userInfo;
                    // console.log("用户昵称为:" + userInfo.nickName);
                    // console.log("用户头像地址为:" + userInfo.avatarUrl);
                    // this.nickName = userInfo.nickName
                    // this.avatarUrl = userInfo.avatarUrl
                    // this.$globalData.userPhoto = userInfo.avatarUrl
                },
                fail: function () {
                    console.error('获取用户信息失败');
                }
            });
        },

        handleUserDestory() {
            uni.request({
                url: 'https://admin.mindepoch.com:8089/UnregisterUser',
                method: 'POST',
                header: {
                    'Content-Type': 'application/x-www-form-urlencoded',
                    'Cookie': `${uni.getStorageSync('session_token')}`,
                },
                data: { id: uni.getStorageSync('wxUid') },
                success:function(res) {
                    console.log(res)
                    uni.showToast({
                        title: '注销成功!',
                        icon: 'none'
                    });
                },
                fail:function(err) {
                    console.log(err)
                }
            })
        }
    }
}
</script>

<style scoped>
.wrapper{
    height: 100vh;
    width: 100vw;
}
.image {
506 507
	height:100%;
	width: 100%;
xhw committed
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525
}
.section{
    
}
.shadowBoard{
    /* 其他样式,如背景大小、位置等 */
    width: 100vw;
    height: 100vh;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    filter: blur(5px);
    z-index: -99;
    position: fixed;
    
}
.swiper{
    padding-top: 320rpx;
526
    position:relative;
xhw committed
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584
}
.CardContent{
    position: absolute;
    top:0;
    left: 50%;
    transform: translateX(-50%);
    height: 100%;
    width: 85%;
    color: #fff;
}
.card{
    position: relative;
    width: 100%;
    height: 100%;
}
.header1{
    font-size: 40rpx;
    margin-top: 20rpx;
    text-align: left;
}
.header2{
    position: absolute;
    bottom:40rpx;
    left: 0;
    font-size: 38rpx;
}
.sdsd{
    text-align: left;
}
.distence{
    margin-top: 20rpx;
}
.detail{
    font-size: 24rpx;
    max-height: 100rpx;
    line-height: 38rpx;
    background-color: #00000039;
    padding: 6rpx;
    border-radius: 10rpx;
    text-align: left;
    overflow-y: scroll;
}
.shadow{
    position: fixed;
    width: 100vw;
    height: 100vh;
    
}
.shadow>image{
    width: auto;
    height: 100%;
}
.btn{
    padding: 0 !important;
    margin: 0 !important;
    display: block;
    z-index: 99;
    border-radius: 24rpx;
585 586
    height: 700rpx;
    width:450rpx;
xhw committed
587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662
    border: 1px solid #0000009a;
    box-shadow: 0 0 20rpx #fff;
}
.userInfoPression{
    background-color: #ffffff;
    height: 350rpx;
    border-radius: 20rpx 20rpx 0 0;
}
.mainInfo{

}
.infoHead{
    text-align: center;
    padding: 42rpx;
    font-weight: 700;
}
.infoFoot{
    display:flex;
    width: 100vw;
    position: absolute;
    bottom: 50rpx;
    left: 0;
}
.infoFoot>Button{
    width: 200rpx;
    height: 80rpx;
    line-height: 80rpx;
    font-size: 32rpx;
    color: #fff;
    
}
.infoFoot>Button:nth-child(1){
    background-color: gray;
}
.infoFoot>Button:nth-child(2){
    background-color: #1AAD19;
}
.ttt{
    position: absolute;
    top:0;
    left: 0;
    z-index: 9;
    width: 100vw;
    height: 100vh;
    background-color: #ffffff;
}
.pisition{
    padding-top: 300rpx;
}
.avatar-wrapper{
    border: 1px solid rgb(192, 176, 176);
    width: 200rpx;
    height: 200rpx;
    margin-top: 25rpx;
}
.avatar{
    width: 150rpx;
    height: 150rpx;
    margin-top: 25rpx;
}
.weui-input{
    border: 1px solid rgb(123, 108, 108);
    margin-top: 300rpx;
    width: 50vw;
    height: 70rpx;
    border-radius: 12rpx;
    margin: 200rpx auto;
}
.tipUserHeader{
    text-align: center;
    margin-top: 20rpx;
    color: rgb(123, 108, 108);
}
.submit{
    width: 250rpx;
}
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679
.scaleToFill{
    position:absolute;
    top:62%;
    left:-10rpx;
    width:100rpx;
    height:100rpx;
    z-index:99;
}
.scaleToFill2{
    transform:rotate(180deg);
    position:absolute;
    top:62%;
    right:-10rpx;
    width:100rpx;
    height:100rpx;
    z-index:99;
}
xhw committed
680
</style>