login.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. <template>
  2. <view class="app">
  3. <!-- logo -->
  4. <view class="header">
  5. <u-avatar src="/static/logo.png" size="200"></u-avatar>
  6. <view class="nickname">登录</view>
  7. <view class="t2">内部报备系统,需登录后才能使用</view>
  8. </view>
  9. <!-- 输入框 -->
  10. <view class="body">
  11. <u-form :model="form1" ref="uForm" style="width: 100%;">
  12. <u-form-item label-width="0" prop="username" :borderBottom="false">
  13. <u-input border placeholder="请输入用户名" v-model="form1.username" type="text" height="90"></u-input>
  14. </u-form-item>
  15. <u-form-item label-width="0" prop="password" :borderBottom="false">
  16. <u-input border placeholder="请输入密码" v-model="form1.password" type="password" height="90"></u-input>
  17. </u-form-item>
  18. </u-form>
  19. <u-gap></u-gap>
  20. <u-button class="bwin-btn-100 u-m-b-10" type="primary" @click="loginHandle" v-if="isSelect">登录</u-button>
  21. <u-button class="bwin-btn-100 u-m-b-10" type="info" v-else disabled>请勾选同意协议内容</u-button>
  22. <!-- <u-button class="bwin-btn-100">取消</u-button> -->
  23. </view>
  24. <!-- 忘记密码导航 -->
  25. <view class="function-row">
  26. <!-- <navigator url="/pages/user/login/login">忘记密码</navigator>
  27. <text style="margin: 0 16rpx;">|</text> -->
  28. <navigator url="/pages/user/login/register">立即注册</navigator>
  29. </view>
  30. <!-- 三方登录 -->
  31. <!-- #ifdef MP-WEIXIN -->
  32. <u-line margin="40rpx 0 0 0"></u-line>
  33. <view class="third-login u-m-b-40">
  34. <u-line margin="0 0 10rpx 0"></u-line>
  35. <button class="login-icon-item scoped-login-btn" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">手机号快捷登录</button>
  36. </view>
  37. <u-modal
  38. v-model="loginByWeixinModalShow"
  39. title="提示"
  40. content="未注册用户请先完成注册并绑定微信后再使用微信登录~"
  41. showCancelButton
  42. showConfirmButton
  43. confirmText="继续微信登录"
  44. @confirm="loginByWeixin()"
  45. ></u-modal>
  46. <!-- #endif -->
  47. <view class="footer">
  48. <u-image v-if="isSelect" src="/static/icon_g_check01.png" @click="isSelect = false" mode="heightFix" height="30rpx" class="img"></u-image>
  49. <u-image v-else src="/static/icon_g_check02.png" @click="isSelect = true" mode="heightFix" height="30rpx" class="img"></u-image>
  50. 我已阅读并同意
  51. <text class="agreement" @click="pageTo('/pages/agreement/agreement?type=user_agreement')">《用户协议》</text>
  52. </view>
  53. </view>
  54. </template>
  55. <script>
  56. var that;
  57. export default {
  58. data() {
  59. // 页面数据变量
  60. return {
  61. isSelect: false,
  62. loginByWeixinModalShow: false, // 微信登录提醒
  63. // init请求返回的数据
  64. data: {},
  65. // 表单请求数据
  66. form1: {
  67. username: '',
  68. password: ''
  69. },
  70. rules: {
  71. username: [
  72. {
  73. required: true,
  74. message: '请输入账号',
  75. // 可以单个或者同时写两个触发验证方式
  76. trigger: 'blur,change'
  77. },
  78. ],
  79. password: [
  80. {
  81. min: 6,
  82. message: '密码不能少于6个字符',
  83. trigger: 'change'
  84. },
  85. ]
  86. },
  87. scrollTop: 0
  88. };
  89. },
  90. onPageScroll(e) {
  91. this.scrollTop = e.scrollTop;
  92. },
  93. // 监听 - 页面每次【加载时】执行(如:前进)
  94. onLoad(options = {}) {
  95. that = this;
  96. that.options = options;
  97. // if (xxx.checkToken()) {
  98. // xxx.toast('您已登录', 'none', 1500, true, function() {
  99. // xxx.navigateToHome();
  100. // });
  101. // }
  102. that.init(options);
  103. },
  104. // 监听 - 页面【首次渲染完成时】执行。注意如果渲染速度快,会在页面进入动画完成前触发
  105. onReady() {
  106. this.$refs.uForm.setRules(this.rules);
  107. },
  108. /**
  109. * 监听 - 点击右上角转发时 文档 https://uniapp.dcloud.io/api/plugins/share?id=onshareappmessage
  110. * 如果删除onShareAppMessage函数,则微信小程序右上角转发按钮会自动变灰
  111. */
  112. onShareAppMessage(options) {},
  113. // 函数
  114. methods: {
  115. pageTo(path) {
  116. if (path === 'dev') {
  117. uni.$msg('开发中~')
  118. return
  119. }
  120. uni.navigateTo({
  121. url: path
  122. })
  123. },
  124. getPhoneNumber (e) {
  125. const dtlObj = e.detail || {}
  126. let _that = this
  127. uni.login({
  128. success: function (res) {
  129. if (res.code) {
  130. uni.api.base.apiwxlogin({
  131. code: res.code,
  132. phone_code: dtlObj.code,
  133. iv: dtlObj.iv,
  134. encrypted_data: dtlObj.encryptedData,
  135. }).then(cData => {
  136. uni.setStorageSync('MD_token', cData.token)
  137. uni.setStorageSync('MD_userInfo', cData)
  138. uni.setStorageSync('MD_phone', cData.phone)
  139. uni.$msg('登录成功~')
  140. _that.getUserInfo()
  141. }).catch(err => {
  142. console.log(err)
  143. })
  144. } else {
  145. console.log('登录失败!' + res.errMsg)
  146. }
  147. }
  148. })
  149. },
  150. // 页面数据初始化函数
  151. async init(options = {}) {
  152. const username = uni.getStorageSync('MD_phone')
  153. this.form1.username = username
  154. },
  155. // 账密登录
  156. loginHandle() {
  157. const _that = this
  158. this.$refs.uForm.validate(valid => {
  159. if (valid) {
  160. uni.api.base.apilogin({
  161. phone: this.form1.username,
  162. password: this.form1.password,
  163. }).then(res => {
  164. uni.setStorageSync('MD_userInfo', res)
  165. uni.setStorageSync('MD_phone', res.phone)
  166. uni.setStorageSync('MD_token', res.token)
  167. uni.$msg('登录成功~')
  168. _that.getUserInfo()
  169. })
  170. } else {
  171. console.log('验证失败');
  172. return;
  173. }
  174. });
  175. // 发送登录请求
  176. // vk.userCenter.login({
  177. // data: {
  178. // username: that.form1.username,
  179. // password: that.form1.password
  180. // },
  181. // success: res => {
  182. // // 成功后的逻辑
  183. // vk.callFunction({
  184. // url: 'client/agent/kh/getAgentInfo',
  185. // needAlert: false
  186. // }).then(res => {
  187. // vk.vuex.set('$user.agentInfo', res.info);
  188. // vk.alert('登录成功', '确定', '提示', function() {
  189. // vk.navigateToHome();
  190. // });
  191. // });
  192. // }
  193. // });
  194. },
  195. getUserInfo () {
  196. uni.api.base.apiuserinfo().then(res => {
  197. uni.reLaunch({
  198. url: '/pages/index/index'
  199. })
  200. uni.setStorageSync('MD_userInfo2', res)
  201. })
  202. uni.api.base.apidicttree().then(res => {
  203. const cObj = res || {}
  204. let newDict = {}
  205. for (let k in cObj) {
  206. const cArr = cObj[k].map(item => {
  207. return {
  208. ...item,
  209. key: item.dict_label,
  210. val: item.dict_value
  211. }
  212. })
  213. newDict[k] = cArr
  214. }
  215. uni.setStorageSync('MD_dict', newDict)
  216. })
  217. },
  218. // 微信登录
  219. loginByWeixin() {
  220. // vk.userCenter.loginByWeixin({
  221. // data: {
  222. // type: 'login' // 无账号不注册
  223. // },
  224. // success: data => {
  225. // // 成功后的逻辑
  226. // vk.callFunction({
  227. // url: 'client/agent/kh/getAgentInfo',
  228. // needAlert: false
  229. // }).then(res => {
  230. // vk.vuex.set('$user.agentInfo', res.info);
  231. // vk.alert('登录成功', '确定', '提示', function() {
  232. // vk.navigateToHome();
  233. // });
  234. // });
  235. // }
  236. // });
  237. }
  238. },
  239. // 监听器
  240. watch: {},
  241. // 计算属性
  242. computed: {}
  243. };
  244. </script>
  245. <style lang="scss" scoped>
  246. .header {
  247. padding-top: 15%;
  248. margin-bottom: 40rpx;
  249. display: flex;
  250. flex-direction: column;
  251. align-items: center;
  252. .avatar {
  253. width: 200rpx;
  254. height: 200rpx;
  255. display: flex;
  256. align-items: center;
  257. justify-content: center;
  258. margin-bottom: 20rpx;
  259. }
  260. .nickname {
  261. font-size: $u-h3;
  262. }
  263. .t2 {
  264. font-size: 24rpx;
  265. color: #999;
  266. }
  267. }
  268. .body {
  269. width: 100%;
  270. display: flex;
  271. flex-direction: column;
  272. align-items: center;
  273. padding: 20rpx 100rpx;
  274. margin: 40rpx 0;
  275. .title {
  276. font-size: $u-p;
  277. margin-bottom: 20rpx;
  278. }
  279. .tips {
  280. font-size: $u-p2;
  281. color: $u-tips-color;
  282. margin-bottom: 60rpx;
  283. }
  284. }
  285. .third-login {
  286. display: flex;
  287. flex-direction: column;
  288. align-items: center;
  289. justify-content: center;
  290. padding: 20rpx;
  291. }
  292. .function-row {
  293. font-size: $u-p2;
  294. display: flex;
  295. align-items: center;
  296. justify-content: center;
  297. margin: 0 auto;
  298. width: 300rpx;
  299. }
  300. .footer {
  301. position: absolute;
  302. width: 100%;
  303. text-align: center;
  304. bottom: 20rpx;
  305. font-size: $u-p2;
  306. color: $u-content-color;
  307. .agreement {
  308. color: $u-theme-color;
  309. }
  310. .img {
  311. display: inline-block;
  312. margin-right: 10rpx;
  313. }
  314. }
  315. .scoped-login-btn {
  316. background: transparent;
  317. border: 0;
  318. outline:0px;
  319. -webkit-appearance: none;
  320. background: #13CE66;
  321. color: #fff;
  322. font-size: 28rpx;
  323. &::after {
  324. display: none;
  325. }
  326. }
  327. </style>