index.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <template>
  2. <!-- index.wxml -->
  3. <view class="container">
  4. <view class="logo">
  5. <cover-image src="/static/pages/resource/img/logo.png"></cover-image>
  6. </view>
  7. <view class="register">
  8. <van-cell-group :border="false">
  9. <van-field :value="phoneNum" type="number" clearable label="手机号" placeholder="请输入您的手机号码" :border="false" @change="onPhoneChange" />
  10. <van-field
  11. v-if="!showPS"
  12. :value="password"
  13. type="password"
  14. use-button-slot
  15. label="密码"
  16. placeholder="请输入您的密码"
  17. :border="false"
  18. @input="onPasswordChange"
  19. icon="closed-eye"
  20. @click-icon="onClickShowPassword"
  21. />
  22. <van-field
  23. v-else
  24. :value="password"
  25. use-button-slot
  26. label="密码"
  27. placeholder="请输入您的密码"
  28. :border="false"
  29. @input="onPasswordChange"
  30. icon="eye-o"
  31. @click-icon="onClickShowPassword"
  32. />
  33. </van-cell-group>
  34. <van-button type="info" custom-class="tijiao" size="large" :round="true" @click="loginAction">登录</van-button>
  35. </view>
  36. <van-toast id="van-toast" />
  37. </view>
  38. </template>
  39. <script>
  40. // pages/staff/login/index.js
  41. let myPro = require('../../../utils/wxRequest.js');
  42. let util = require('../../../utils/util.js');
  43. var app = getApp();
  44. export default {
  45. data() {
  46. return {
  47. phoneNum: '',
  48. password: '',
  49. showPS: false,
  50. latitude: 0,
  51. longitude: 0
  52. };
  53. }
  54. /**
  55. * 生命周期函数--监听页面加载
  56. */,
  57. onLoad: function (options) {
  58. // wx.hideHomeButton()
  59. },
  60. /**
  61. * 生命周期函数--监听页面初次渲染完成
  62. */
  63. onReady: function () {},
  64. /**
  65. * 生命周期函数--监听页面显示
  66. */
  67. onShow: function () {
  68. console.log(uni.getStorageSync('staffphone'));
  69. var that = this;
  70. var staffphone = uni.getStorageSync('staffphone');
  71. if (staffphone != undefined && staffphone != null) {
  72. this.setData({
  73. phoneNum: staffphone
  74. });
  75. }
  76. uni.getLocation({
  77. type: 'wgs84',
  78. // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
  79. success: function (res) {
  80. that.setData({
  81. latitude: res.latitude,
  82. longitude: res.longitude
  83. });
  84. }
  85. });
  86. },
  87. /**
  88. * 生命周期函数--监听页面隐藏
  89. */
  90. onHide: function () {},
  91. /**
  92. * 生命周期函数--监听页面卸载
  93. */
  94. onUnload: function () {},
  95. /**
  96. * 页面相关事件处理函数--监听用户下拉动作
  97. */
  98. onPullDownRefresh: function () {},
  99. /**
  100. * 页面上拉触底事件的处理函数
  101. */
  102. onReachBottom: function () {},
  103. /**
  104. * 用户点击右上角分享
  105. */
  106. onShareAppMessage: function () {},
  107. methods: {
  108. onPhoneChange(e) {
  109. this.setData({
  110. phoneNum: e.detail
  111. });
  112. },
  113. onPasswordChange(e) {
  114. this.setData({
  115. password: e.detail
  116. });
  117. },
  118. onClickShowPassword() {
  119. this.setData({
  120. showPS: !this.showPS
  121. });
  122. },
  123. loginAction() {
  124. if (this.phoneNum === undefined || this.phoneNum === null || this.phoneNum === '') {
  125. Toast('请输入手机号');
  126. return;
  127. }
  128. if (this.password === undefined || this.password === null || this.password === '') {
  129. Toast('请输入密码');
  130. return;
  131. }
  132. uni.showLoading({
  133. mask: true
  134. });
  135. var that = this;
  136. var params = {
  137. phone: this.phoneNum,
  138. password: this.password
  139. };
  140. myPro
  141. .wxRequest('staff/login', 'POST', params)
  142. .then((res) => {
  143. uni.hideLoading();
  144. var res = res.data;
  145. console.log(res);
  146. if (res.code === 200) {
  147. app.globalData.token = res.result.token;
  148. app.globalData.xxInfo = res.result.user;
  149. app.globalData.showedWaterDialog = false;
  150. uni.setStorage({
  151. key: 'xxInfo',
  152. data: res.result.user
  153. });
  154. uni.setStorage({
  155. key: 'token',
  156. data: res.result.token
  157. });
  158. uni.setStorage({
  159. key: 'staffphone',
  160. data: this.phoneNum
  161. });
  162. uni.switchTab({
  163. url: '../index/index'
  164. });
  165. } else {
  166. Toast(res.msg);
  167. } // wx.reLaunch({
  168. // url: '/pages/index/index'
  169. // });
  170. })
  171. .catch((err) => {
  172. console.log('报错信息', err);
  173. uni.showToast({
  174. title: err,
  175. icon: 'none'
  176. });
  177. }); // wx.redirectTo({
  178. // url: '../../index/index'
  179. // });
  180. }
  181. }
  182. };
  183. </script>
  184. <style>
  185. /* pages/staff/login/index.wxss */
  186. .logo {
  187. width: 293rpx;
  188. height: 300rpx;
  189. margin: 30rpx auto 0;
  190. }
  191. .register {
  192. margin-top: 88rpx;
  193. padding: 0 40rpx;
  194. }
  195. .register .van-cell {
  196. padding: 50rpx 0 20rpx;
  197. border-bottom: 2rpx solid rgba(235, 235, 235, 1);
  198. }
  199. .register .van-cell__title {
  200. min-width: 102rpx !important;
  201. max-width: 102rpx !important;
  202. margin-right: 30rpx;
  203. }
  204. .van-button.sendvericode {
  205. display: inline-block;
  206. width: 198rpx;
  207. height: 48rpx !important;
  208. border: 2rpx solid rgba(85, 141, 224, 1);
  209. border-radius: 8rpx;
  210. color: rgba(85, 141, 224, 1);
  211. font-size: 22rpx;
  212. line-height: 48rpx !important;
  213. text-align: center;
  214. background: #ffffff;
  215. }
  216. .van-button.sendvericode.sended {
  217. border: 2rpx solid rgba(184, 188, 204, 1);
  218. color: rgba(184, 188, 204, 1);
  219. }
  220. .sendvericode.van-button--plain.van-button--primary.sended {
  221. color: rgba(184, 188, 204, 1);
  222. }
  223. .sendvericode.van-button--normal {
  224. padding: 0;
  225. font-size: 22rpx;
  226. }
  227. .sendvericode.van-button--plain.van-button--primary {
  228. color: #558de0;
  229. }
  230. .tijiao.van-button {
  231. margin-top: 60rpx;
  232. font-size: 30rpx !important;
  233. height: 80rpx !important;
  234. line-height: 80rpx !important;
  235. border-radius: 12rpx !important;
  236. background: rgba(85, 141, 224, 1);
  237. }
  238. .tijiao.van-button.van-button--info {
  239. border: 0 none;
  240. }
  241. .agreement {
  242. margin-top: 30rpx;
  243. }
  244. .agreement .text {
  245. display: inline-block;
  246. color: #558de0;
  247. font-size: 22rpx !important;
  248. }
  249. .van-radio__label {
  250. font-size: 22rpx !important;
  251. color: #b8bccc;
  252. }
  253. .wechat_wrap {
  254. padding-top: 214rpx;
  255. width: 576rpx;
  256. margin: 0 auto;
  257. text-align: center;
  258. }
  259. .wechat_wrap .wechat_title {
  260. color: rgba(82, 86, 102, 1);
  261. font-size: 24rpx;
  262. }
  263. .wechat_wrap .wechat_title::before,
  264. .wechat_wrap .wechat_title::after {
  265. content: '';
  266. display: inline-block;
  267. width: 200rpx;
  268. height: 1rpx;
  269. background: rgba(184, 188, 204, 1);
  270. vertical-align: middle;
  271. }
  272. .wechat_wrap .wechat_title::before {
  273. margin-right: 40rpx;
  274. }
  275. .wechat_wrap .wechat_title::after {
  276. margin-left: 40rpx;
  277. }
  278. .wechat_wrap .wechat {
  279. margin: 60rpx auto 123rpx;
  280. text-align: center;
  281. }
  282. .wechat_wrap .wechat .icon {
  283. display: inline-block;
  284. width: 88rpx;
  285. height: 88rpx;
  286. }
  287. .wechat_wrap .wechat .info {
  288. margin-top: 20rpx;
  289. font-size: 22rpx;
  290. font-weight: 500;
  291. color: rgba(82, 86, 102, 1);
  292. }
  293. </style>