mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-15 03:25:06 +08:00
多模块重构 12:修改项目名字,按照新的规则
This commit is contained in:
91
yudao-ui-app-tmp/pages/index/index.js
Executable file
91
yudao-ui-app-tmp/pages/index/index.js
Executable file
@ -0,0 +1,91 @@
|
||||
// index.js
|
||||
|
||||
const common=require('../../utils/common.js')
|
||||
// 获取应用实例
|
||||
const app = getApp()
|
||||
|
||||
Page({
|
||||
data: {
|
||||
motto: 'Hello World',
|
||||
userInfo: {},
|
||||
hasUserInfo: false,
|
||||
canIUse: wx.canIUse('button.open-type.getUserInfo'),
|
||||
canIUseGetUserProfile: false,
|
||||
canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName'), // 如需尝试获取用户信息可改为false
|
||||
holderText: 'to be auth'
|
||||
},
|
||||
// 事件处理函数
|
||||
bindViewTap() {
|
||||
wx.navigateTo({
|
||||
url: '../logs/logs'
|
||||
})
|
||||
},
|
||||
onLoad() {
|
||||
if (wx.getUserProfile) {
|
||||
this.setData({
|
||||
canIUseGetUserProfile: true
|
||||
})
|
||||
}
|
||||
},
|
||||
getUserProfile(e) {
|
||||
// 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
|
||||
wx.getUserProfile({
|
||||
desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
|
||||
success: (res) => {
|
||||
console.log(res)
|
||||
this.setData({
|
||||
userInfo: res.userInfo,
|
||||
hasUserInfo: true
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
getUserInfo(e) {
|
||||
// 不推荐使用getUserInfo获取用户信息,预计自2021年4月13日起,getUserInfo将不再弹出弹窗,并直接返回匿名的用户个人信息
|
||||
console.log(e)
|
||||
this.setData({
|
||||
userInfo: e.detail.userInfo,
|
||||
hasUserInfo: true
|
||||
})
|
||||
},
|
||||
// 小程序登录 https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/login.html
|
||||
wxLogin(e){
|
||||
let page=this;
|
||||
wx.login({
|
||||
success (res) {
|
||||
console.log("res:")
|
||||
console.log(res)
|
||||
if (res.code) {
|
||||
//发起网络请求
|
||||
console.log('发起网络请求'+common.baseurl)
|
||||
wx.request({
|
||||
url: common.baseurl+'/api/social-login2',
|
||||
method: "POST",
|
||||
data: {
|
||||
code: res.code,
|
||||
state: 'empty',
|
||||
type: 33,
|
||||
username: '15601691300',
|
||||
password: 'admin123'
|
||||
},
|
||||
header: {
|
||||
'content-type': 'application/json' // 默认值
|
||||
},
|
||||
success: function(res) {
|
||||
console.log(res.data)
|
||||
let holder="auth success, token:"+res.data.data.token
|
||||
page.setData({holderText: holder})
|
||||
},
|
||||
fail: function(data){
|
||||
console.error("请求出错");
|
||||
console.error(data)
|
||||
}
|
||||
|
||||
})
|
||||
} else {
|
||||
console.log('登录失败!' + res.errMsg)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
3
yudao-ui-app-tmp/pages/index/index.json
Executable file
3
yudao-ui-app-tmp/pages/index/index.json
Executable file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"usingComponents": {}
|
||||
}
|
29
yudao-ui-app-tmp/pages/index/index.wxml
Executable file
29
yudao-ui-app-tmp/pages/index/index.wxml
Executable file
@ -0,0 +1,29 @@
|
||||
<!--index.wxml-->
|
||||
<view class="container">
|
||||
<view class="userinfo">
|
||||
<block wx:if="{{canIUseOpenData}}">
|
||||
|
||||
|
||||
</block>
|
||||
<block wx:elif="{{!hasUserInfo}}">
|
||||
<button wx:if="{{canIUseGetUserProfile}}" bindtap="getUserProfile"> 获取头像昵称 </button>
|
||||
<button wx:elif="{{canIUse}}" open-type="getUserInfo" bindgetuserinfo="getUserInfo"> 获取头像昵称 </button>
|
||||
<view wx:else> 请使用1.4.4及以上版本基础库 </view>
|
||||
</block>
|
||||
<block wx:else>
|
||||
<image bindtap="bindViewTap" class="userinfo-avatar" src="{{userInfo.avatarUrl}}" mode="cover"></image>
|
||||
<text class="userinfo-nickname">{{userInfo.nickName}}</text>
|
||||
</block>
|
||||
</view>
|
||||
<view class="usermotto">
|
||||
|
||||
</view>
|
||||
|
||||
|
||||
|
||||
<text style="position: relative; left: 1rpx; top: -476rpx">授权登录测试1024</text>
|
||||
|
||||
<button style="position: relative; left: 0rpx; top: -361rpx" type="primary" id="login-button" bindtap="wxLogin">点击授权登录</button>
|
||||
|
||||
<text style="position: relative; left: 1rpx; top: -272rpx" id="login-user-id">{{holderText}}</text>
|
||||
</view>
|
19
yudao-ui-app-tmp/pages/index/index.wxss
Executable file
19
yudao-ui-app-tmp/pages/index/index.wxss
Executable file
@ -0,0 +1,19 @@
|
||||
/**index.wxss**/
|
||||
.userinfo {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
color: #aaa;
|
||||
}
|
||||
|
||||
.userinfo-avatar {
|
||||
overflow: hidden;
|
||||
width: 128rpx;
|
||||
height: 128rpx;
|
||||
margin: 20rpx;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.usermotto {
|
||||
margin-top: 200px;
|
||||
}
|
Reference in New Issue
Block a user