register.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <template>
  2. <!--pages/register/register.wxml-->
  3. <view class="register">
  4. <view class="con">
  5. <image src="../../static/logo.png"></image>
  6. <!-- 登录 -->
  7. <view class="login-form">
  8. <view :class="['item',errorTips==1? 'error':'']">
  9. <view class="account">
  10. <text class="input-item">账号</text>
  11. <input type="text" @input="getInputVal" data-type="account" placeholder-class="inp-palcehoder" placeholder="请输入账号名称"></input>
  12. </view>
  13. <view class="error-text" v-if="errorTips==1"><text class="warning-icon">!</text>请输入账号!</view>
  14. </view>
  15. <view :class="['item',errorTips==2? 'error':'']">
  16. <view class="account">
  17. <text class="input-item">密码</text>
  18. <input type="password" @input="getInputVal" data-type="password" placeholder-class="inp-palcehoder" placeholder="请输入密码"></input>
  19. </view>
  20. <view class="error-text" v-if="errorTips==2"><text class="warning-icon">!</text>请输入密码!</view>
  21. </view>
  22. <view class="operate">
  23. <view class="to-register" @tap="toLogin">已有账号?<text>去登录></text></view>
  24. </view>
  25. </view>
  26. <view>
  27. <button class="authorized-btn" @tap="toRegister">注册</button>
  28. <button class="to-idx-btn" @tap="toIndex">回到首页</button>
  29. </view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. // pages/register/register.js
  35. var http = require("../../utils/http");
  36. var util = require("../../utils/util.js");
  37. import { encrypt } from '../../utils/crypto.js'
  38. export default {
  39. data() {
  40. return {
  41. errorTips: 0, // 输入错误提示: 1账号输入 2密码输入
  42. principal: '', // 账号
  43. credentials: '', // 密码
  44. };
  45. },
  46. components: {},
  47. props: {},
  48. computed: {},
  49. /**
  50. * 生命周期函数--监听页面加载
  51. */
  52. onLoad: function(options) {},
  53. /**
  54. * 生命周期函数--监听页面初次渲染完成
  55. */
  56. onReady: function() {},
  57. /**
  58. * 生命周期函数--监听页面显示
  59. */
  60. onShow: function() {
  61. //头部导航标题
  62. uni.setNavigationBarTitle({
  63. title: "用户注册"
  64. });
  65. },
  66. /**
  67. * 生命周期函数--监听页面隐藏
  68. */
  69. onHide: function() {},
  70. /**
  71. * 生命周期函数--监听页面卸载
  72. */
  73. onUnload: function() {},
  74. /**
  75. * 页面相关事件处理函数--监听用户下拉动作
  76. */
  77. onPullDownRefresh: function() {},
  78. /**
  79. * 页面上拉触底事件的处理函数
  80. */
  81. onReachBottom: function() {},
  82. /**
  83. * 用户点击右上角分享
  84. */
  85. onShareAppMessage: function() {},
  86. methods: {
  87. /**
  88. * 输入框的值
  89. */
  90. getInputVal: function(e) {
  91. const type = e.currentTarget.dataset.type;
  92. if (type == 'account') {
  93. this.setData({
  94. principal: e.detail.value
  95. });
  96. } else if (type == 'password') {
  97. this.setData({
  98. credentials: e.detail.value
  99. });
  100. }
  101. },
  102. /**
  103. * 注册
  104. */
  105. toRegister() {
  106. if (this.principal.length == 0) {
  107. this.setData({
  108. errorTips: 1
  109. })
  110. return
  111. } else if (this.credentials.length == 0) {
  112. this.setData({
  113. errorTips: 2
  114. })
  115. return
  116. } else {
  117. this.setData({
  118. errorTips: 0
  119. })
  120. uni.showLoading();
  121. var params = {
  122. url: "/user/register",
  123. method: "post",
  124. data: {
  125. // appType: 1,
  126. // 应用类型 1小程序 2微信公众号 3 PC 4 H5
  127. userName: this.principal,
  128. passWord: encrypt(this.credentials),
  129. },
  130. callBack: res => {
  131. uni.hideLoading();
  132. uni.showToast({
  133. title: "注册成功,请登录",
  134. icon: "none",
  135. duration: 1500
  136. })
  137. setTimeout(() => {
  138. uni.navigateTo({
  139. url: "/pages/accountLogin/accountLogin"
  140. })
  141. }, 1800)
  142. // wx.setStorageSync('loginResult', res);
  143. // wx.setStorageSync('token', 'bearer' + res.access_token);
  144. }
  145. };
  146. http.request(params);
  147. }
  148. },
  149. /**
  150. * 去登陆
  151. */
  152. toLogin: function() {
  153. uni.navigateTo({
  154. url: "/pages/accountLogin/accountLogin"
  155. });
  156. },
  157. /**
  158. * 回到首页
  159. */
  160. toIndex: function() {
  161. uni.switchTab({
  162. url: '/pages/index/index'
  163. });
  164. // this.$Router.pushTab('/pages/index/index')
  165. }
  166. }
  167. }
  168. </script>
  169. <style>
  170. @import "./register.css";
  171. </style>