account-login.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <view class="con">
  3. <view class="logo">
  4. <image :src="stationLoginLogoImg" mode="heightFix" @tap="toIndex" />
  5. </view>
  6. <!-- 登录 -->
  7. <view v-if="!isForgetPassword" class="login-form">
  8. <view :class="['item',errorTips==1 && !isForgetPassword? 'error':'']">
  9. <view class="account">
  10. <text class="input-item">账号</text>
  11. <input type="text" data-type="account" placeholder-class="inp-palcehoder" placeholder="请输入账号" @input="getInputVal">
  12. </view>
  13. <view v-if="errorTips==1 && !isForgetPassword" class="error-text"><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" data-type="password" placeholder-class="inp-palcehoder" placeholder="请输入密码" @input="getInputVal">
  19. </view>
  20. <view v-if="errorTips==2" class="error-text"><text class="warning-icon">!</text>请输入密码</view>
  21. </view>
  22. </view>
  23. <view v-if="!isForgetPassword">
  24. <button class="authorized-btn" @tap="login">登录</button>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. var http = require('../../utils/http')
  30. import { encrypt } from '@/utils/crypto'
  31. export default {
  32. components: {},
  33. props: {},
  34. data() {
  35. return {
  36. principal: '',
  37. credentials: '',
  38. isForgetPassword: false, // 是否修改密码
  39. isPersonalCenter: false, // 是否从个人中心页面跳转过来
  40. stationLoginLogoImg: '',
  41. errorTips: 0 // 错误提示
  42. }
  43. },
  44. /**
  45. * 生命周期函数--监听页面加载
  46. */
  47. onLoad: function(options) {
  48. if (options.isForgetPassword) {
  49. this.isForgetPassword = options.isForgetPassword
  50. }
  51. if (options.isPersonalCenter) {
  52. this.isPersonalCenter = options.isPersonalCenter
  53. }
  54. this.getUniWebConfig()
  55. },
  56. /**
  57. * 生命周期函数--监听页面初次渲染完成
  58. */
  59. onReady: function() {},
  60. /**
  61. * 生命周期函数--监听页面显示
  62. */
  63. onShow: function() {},
  64. /**
  65. * 生命周期函数--监听页面隐藏
  66. */
  67. onHide: function() {},
  68. /**
  69. * 生命周期函数--监听页面卸载
  70. */
  71. onUnload: function() {},
  72. /**
  73. * 页面相关事件处理函数--监听用户下拉动作
  74. */
  75. onPullDownRefresh: function() {},
  76. /**
  77. * 页面上拉触底事件的处理函数
  78. */
  79. onReachBottom: function() {},
  80. /**
  81. * 用户点击右上角分享
  82. */
  83. onShareAppMessage: function() {},
  84. methods: {
  85. /**
  86. * 初始加载数据
  87. */
  88. getUniWebConfig: function() {
  89. var params = {
  90. url: '/webConfig/getStationWebConfig',
  91. method: 'GET',
  92. data: {},
  93. callBack: res => {
  94. this.setData({
  95. stationLoginLogoImg: res.stationLoginLogoImg
  96. })
  97. uni.setStorageSync('stationLoginLogoImg', this.stationLoginLogoImg)
  98. }
  99. }
  100. http.request(params)
  101. },
  102. /**
  103. * 输入框的值
  104. */
  105. getInputVal: function(e) {
  106. const type = e.currentTarget.dataset.type
  107. if (type == 'account') {
  108. this.setData({
  109. principal: e.detail.value
  110. })
  111. } else if (type == 'password') {
  112. this.setData({
  113. credentials: e.detail.value
  114. })
  115. }
  116. },
  117. /**
  118. * 登录
  119. */
  120. login() {
  121. if (!this.principal) {
  122. this.setData({
  123. errorTips: 1
  124. })
  125. return
  126. } else if (this.credentials.length == 0) {
  127. this.setData({
  128. errorTips: 2
  129. })
  130. return
  131. } else {
  132. this.setData({
  133. errorTips: 0
  134. })
  135. var params = {
  136. url: '/stationLogin',
  137. method: 'POST',
  138. data: {
  139. userName: this.principal,
  140. passWord: encrypt(this.credentials),
  141. tempUid: uni.getStorageSync('sTempUid')
  142. },
  143. callBack: res => {
  144. http.loginSuccess(res, () => {
  145. uni.showToast({
  146. title: '登录成功!',
  147. icon: 'none',
  148. complete() {
  149. uni.reLaunch({
  150. url: '/pages/index/index'
  151. })
  152. }
  153. })
  154. })
  155. }
  156. }
  157. http.request(params)
  158. }
  159. },
  160. /**
  161. * 修改密码(登录页修改密码按钮)
  162. */
  163. forgotPassword() {
  164. this.setData({
  165. isForgetPassword: true
  166. })
  167. },
  168. /**
  169. * 回到首页
  170. */
  171. toIndex() {
  172. wx.navigateTo({
  173. url: '/pages/index/index'
  174. })
  175. }
  176. }
  177. }
  178. </script>
  179. <style>
  180. @import "./account-login.css";
  181. </style>