123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- // pages/register.js
- const app = getApp()
- const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
- const {upLoad} = require('../../utils/util');
- var clientWidth = wx.getSystemInfoSync().windowWidth;
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- avatarUrl: defaultAvatarUrl,
- theme: wx.getSystemInfoSync().theme,
- },
- /**
- * 生命周期函数--监听页面加载
- */
-
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- },
-
-
-
- onLoad() {
- this.setData({
- left:clientWidth/2-40+'px'
- })
- wx.onThemeChange((result) => {
- this.setData({
- theme: result.theme
- })
- })
- },
- // onChooseAvatar(e) {
- // const { avatarUrl } = e.detail
- // this.setData({
- // avatarUrl,
- // })
- // },
- onChooseAvatar1(){
- wx.chooseImage({
- count: 1,//可选择图片数量
- sizeType: ['compressed'],//压缩图片
- sourceType: ['album','camera'],//来源
- success: (res) => {
- this.uploadImage(res.tempFilePaths[0]);
- }
- })
- },
- uploadImage(imagePath){
- upLoad( imagePath ).then((res) => {
- console.log(res);
- this.setData({
- avatarUrl: res.Url
- });
- wx.setStorage({
- key: 'avatarUrl',
- data: res.Url,
- success: function() {
- console.log('写入avatarUrl缓存成功')
- },
- fail:function() {
- console.log('写入avatarUrl发生错误')
- }
- });
- })
- },
- onInputUsername:function(e){
- console.log(e);
- wx.setStorage({
- key: 'nickName',
- data: e.detail.value,
- success: function() {
- console.log('写入nickName缓存成功')
- },
- fail:function() {
- console.log('写入nickName发生错误')
- }
- })
- },
- register(){
- var avatar = wx.getStorageSync('avatarUrl');
- var name = wx.getStorageSync('nickName');
- console.log(avatar);
- console.log(name);
- wx.request({
- url: 'http://192.168.31.29:8084/user/register',
- method: 'POST',
- data: {
- avatar: avatar,
- name: name,
- vid: wx.getStorageSync('vid'),
- phone: '',
- sign: '',
- },
- success(res){
- console.log(res);
- wx.request({
- url: 'http://192.168.31.29:8084/user/login',
- method: 'POST',
- header: {
- 'content-type': 'application/x-www-form-urlencoded'
- },
- data:{
- vid: wx.getStorageSync('vid')
- },
-
- success(res){
- console.log(res);
- wx.setStorageSync('token', res.data.data.token);
- wx.setStorageSync('uid', res.data.data.Uid);
- wx.switchTab({
- url: '/pages/home/home',
- })
- }
- })
- }
- })
- }
- })
|