| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- <template>
- <view class="content">
- <div class="self-inf">
- <div class="img-name-box" v-if="isAuth">
- <image :src="userHeadImg" class="heade-img" mode="aspectFill"></image>
- <p class="nickname">{{ userNickName }}</p>
- </div>
- <view class="img-name-box" v-if="!isAuth">
- <image src="/static/auth-icon.png" class="heade-img" mode="aspectFill"></image>
- <button @click="getAuth()" class="auth-btn">授权登录</button>
- </view>
- <image class="bg-img" :src="swiperBackground" mode="aspectFill"></image>
- </div>
- <div class="options">
- <div v-for="(item, idx) in list" :key="idx" class="options-item" @click="goDetailFn(idx, item.url)" v-if="item.isShow">
- <div class="img-box">
- <img :src="item.icoin" alt="" class="options-item-img" />
- </div>
- <div class="options-item-name">
- {{ item.name }}
- </div>
- </div>
- </div>
- </view>
- </template>
- <script>
- import md5 from "@/common/md5.js";
- export default {
- components: {
- },
- data() {
- return {
- isAuth: true,
- userHeadImg: "",
- userNickName: "",
- list: [
- {
- icoin: "/static/upload.png",
- name: "内容上传" ,
- url: "/pages/index/upload/upload",
- isShow:true,
- },
- {
- icoin: "/static/sign.png",
- name: "发布记录" ,
- url: "/pages/index/record/record",
- isShow:true,
- },
- ],
- };
- },
- async onLoad() {
- // setTimeout(()=>{
- // this.getUserInfo()
- // },1000)
- await this.$getOpenId
- this.getUserInfo()
- },
- onShow() {
- },
- methods: {
- getUserInfo() {
- let md5Sign = md5(
- "method=" +
- "user" +
- "×tamp=" +
- getApp().globalData.globalTimestamp +
- "&secret=" +
- getApp().globalData.secret
- );
- let url =
- getApp().globalData.shareUrl +
- "api/api.php" +
- "?method=user&action=info_by_openid×tamp=" +
- getApp().globalData.globalTimestamp +
- "&sign=" +
- md5Sign;
- uni.request({
- url: url,
- method: "POST",
- header: {
- "content-type": "application/x-www-form-urlencoded",
- },
- data: {
- openid:getApp().globalData.open_id,
- },
- success: (res) => {
- if (res.data.code === 200) {
- if (res.data.data.nickname) {
- this.isAuth = true;
- this.userHeadImg = res.data.data.headimg;
- this.userNickName = res.data.data.nickname;
- getApp().globalData.user_department = res.data.data.department;
- getApp().globalData.user_real_name = res.data.data.real_name;
- } else {
- this.isAuth = false;
- }
- }
- },
- fail: () => {
- console.log("连接失败");
- },
- });
- },
- uploadUserInfo(name,head){
- let md5Sign = md5(
- "method=" +
- "user" +
- "×tamp=" +
- getApp().globalData.globalTimestamp +
- "&secret=" +
- getApp().globalData.secret
- );
- let url =
- getApp().globalData.shareUrl +
- "api/api.php" +
- "?method=user&action=update×tamp=" +
- getApp().globalData.globalTimestamp +
- "&sign=" +
- md5Sign;
- uni.request({
- url: url,
- method: "POST",
- header: {
- "content-type": "application/x-www-form-urlencoded",
- },
- data: {
- nickname:name,
- headimg:head,
- openid:getApp().globalData.open_id
- },
- success: (res) => {
- if (res.data.code === 200) {
- }
- },
- fail: () => {
- console.log("连接失败");
- },
- });
- },
- getAuth() {
- uni.getUserProfile({
- desc:'登录',
- success:(res)=> {
- this.userHeadImg = res.userInfo.avatarUrl;
- this.userNickName = res.userInfo.nickName;
- this.uploadUserInfo(res.userInfo.nickName,res.userInfo.avatarUrl)
- this.isAuth = true;
- getApp().globalData.isAuth = true;
- },
- fail:(err)=> {
- console.log(err)
- getApp().globalData.isAuth = false;
- getApp().globalData.globalAuth = false;
- this.isAuth = false;
- }
- })
- },
- goDetailFn(index, url) {
- let that = this;
- if(!that.isAuth){
- uni.showToast({
- title: "您还没有授权",
- duration: 2500,
- icon: "none",
- });
- return;
- }
- switch (index) {
- case 0: //内容上传
- uni.navigateTo({
- url,
- });
- break;
- case 1: //发布记录
- uni.navigateTo({
- url,
- });
- break;
- }
- },
-
- },
- };
- </script>
- <style lang="scss" scoped>
- .content {
- display: flex;
- flex-direction: column;
- .self-inf {
- position: relative;
- height: 360rpx;
- width: 100%;
- display: flex;
- margin-bottom: 80rpx;
- background-color: #c2e3e6;
- // border-radius: 0rpx 0rpx 100% 100%;
- .img-name-box {
- height: 150rpx;
- margin-top:80rpx;
- display: flex;
- align-items: center;
- z-index: 99999;
- .auth-btn {
- margin-left: 30rpx;
- margin-top: 20rpx;
- font-size: 28rpx;
- background-color: #02a7f0;
- color: #fff;
- }
- .heade-img {
- z-index: 1;
- width: 100rpx;
- height: 100rpx;
- border-radius: 50%;
- margin-left: 80rpx;
- }
- }
- .bg-img {
- z-index: -1;
- position: absolute;
- width: 100%;
- height: 100%;
- // border-radius: 0rpx 0rpx 70rpx 70rpx;
- }
- .nickname {
- font-weight: 600;
- font-size: 28rpx;
- margin-left: 30rpx;
- margin-top: 20rpx;
- color: #ffffff;
- letter-spacing: 1rpx;
- }
- }
- .options {
- padding: 70rpx;
- z-index: 99;
- position: relative;
- top: -270rpx;
- .options-item {
- background-color: #fff;
- display: flex;
- box-shadow: 0px 4rpx 32rpx rgba(0, 0, 0, 0.1);
- border-radius: 32rpx;
- margin-top: 20px;
- height: 150rpx;
- align-items: center;
- .img-box {
- margin-left: 40rpx;
- .options-item-img {
- width: 56rpx;
- height: 56rpx;
- }
- }
- .options-item-name {
- margin-left: 40rpx;
- font-weight: 600;
- font-size: 30rpx;
- margin-bottom: 10rpx;
- }
- }
- }
- }
- .fontGrey {
- color: $uni-text-color-grey;
- }
- </style>
|