login.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. <template>
  2. <view class="container-wrap my-fade-in" :style="{background: 'url(' + loginBg + ')'}">
  3. <uni-status-bar></uni-status-bar>
  4. <u-top-tips ref="uTips"></u-top-tips>
  5. <view class="container my-flex">
  6. <!-- 登录表单 -->
  7. <view class="form-wrap flex-column-center">
  8. <view class="logo-wrap my-flex">
  9. <view class="logo">
  10. <image src="../../static/images/LOGO.png" mode=""></image>
  11. </view>
  12. </view>
  13. <view class="form">
  14. <u-form :model="form" ref="uForm">
  15. <u-form-item :border-bottom="false" prop="username">
  16. <u-input style="font-size: 30rpx;" :accountIcon="true" height="72" :border="true"
  17. placeholder="请输入账号" v-model="form.username" />
  18. </u-form-item>
  19. <u-form-item :border-bottom="false" style="position: relative;" prop="password">
  20. <u-input @confirm="handleSubmit" style="font-size: 30rpx;" type="password" :border="true"
  21. placeholder="请输入密码" height="72" v-model="form.password" />
  22. <!-- <span class="forget my-fontsize-Small" @tap="toggleForget">忘记密码</span> -->
  23. </u-form-item>
  24. <!-- <u-form-item :border-bottom="false" v-if="isDev">
  25. <u-input style="font-size: 24rpx;" height="72" :border="true" placeholder="请输入IP" v-model="ip" />
  26. </u-form-item> -->
  27. <u-form-item :border-bottom="false">
  28. <u-button throttleTime="300" type="primary" style="width: 100%;margin-top: 30rpx;"
  29. @click="login">立即登录</u-button>
  30. </u-form-item>
  31. <u-form-item :border-bottom="false" style="margin-top: 70rpx;">
  32. <u-checkbox-group @change="checkboxGroupChange">
  33. <u-checkbox v-model="remember">记住用户名</u-checkbox>
  34. </u-checkbox-group>
  35. </u-form-item>
  36. </u-form>
  37. </view>
  38. <view class="bottom-pic-wrap flex-column-center">
  39. <view class="bottom-pic">
  40. <image src="../../static/images/login-pic.png" mode="heightFix"></image>
  41. </view>
  42. </view>
  43. </view>
  44. <view class="version" v-if="$storage.getStorageSync('version')">
  45. v{{ $storage.getStorageSync('version') || plus.runtime.version }}
  46. </view>
  47. </view>
  48. </view>
  49. </template>
  50. <script>
  51. import loginBg from '@/static/images/login-bg.png'
  52. import {
  53. mapActions
  54. } from 'vuex'
  55. import config from '@/libs/config/config.js'
  56. import w_md5 from "../../js_sdk/zww-md5/w_md5.js"
  57. export default {
  58. data() {
  59. return {
  60. loginBg,
  61. ip: '',
  62. remember: true,
  63. form: {
  64. tenantId: '000000',
  65. username: 'admin',
  66. password: 'admin',
  67. //账号类型
  68. type: 'loginWithoutVerificationCode',
  69. //验证码的值
  70. code: '',
  71. //验证码的索引
  72. key: '',
  73. grant_type: 'captcha',
  74. },
  75. rules: {
  76. account: [{
  77. required: true,
  78. message: '账号不能为空',
  79. // 可以单个或者同时写两个触发验证方式
  80. trigger: ['blur']
  81. },
  82. {
  83. pattern: /^[0-9a-zA-Z]*$/g,
  84. // 正则检验前先将值转为字符串
  85. transform(value) {
  86. return String(value);
  87. },
  88. message: '只能包含字母或数字',
  89. trigger: ['change']
  90. }
  91. ],
  92. password: [{
  93. required: true,
  94. message: '密码不能为空',
  95. // 可以单个或者同时写两个触发验证方式
  96. trigger: ['blur']
  97. }]
  98. }
  99. };
  100. },
  101. methods: {
  102. ...mapActions({
  103. setToken: 'user/setToken',
  104. setUserInfo: 'user/setUserInfo'
  105. }),
  106. handleSubmit() {
  107. this.login()
  108. },
  109. login() {
  110. function filter(str) { // 特殊字符转义
  111. str += ''; // 隐式转换
  112. str = str.replace(/%/g, '%25');
  113. str = str.replace(/\+/g, '%2B');
  114. str = str.replace(/ /g, '%20');
  115. str = str.replace(/\//g, '%2F');
  116. str = str.replace(/\?/g, '%3F');
  117. str = str.replace(/&/g, '%26');
  118. str = str.replace(/\=/g, '%3D');
  119. str = str.replace(/#/g, '%23');
  120. return str;
  121. }
  122. function formateObjToParamStr(paramObj) {
  123. const sdata = [];
  124. for (let attr in paramObj) {
  125. sdata.push(`${attr}=${filter(paramObj[attr])}`);
  126. }
  127. return sdata.join('&');
  128. }
  129. const loginForm = {...this.form}
  130. loginForm.password = w_md5.hex_md5_32(loginForm.password)
  131. console.log(this.form)
  132. this.$utils.formValidate(this.$refs.uForm).then(() => {
  133. uni.request({
  134. url: 'http://36.134.91.96:10001/api' + '/blade-auth/oauth/token?' + formateObjToParamStr(loginForm),
  135. method: 'POST',
  136. header: {
  137. 'Content-Type': 'application/json',
  138. 'Captcha-Key': loginForm.key,
  139. 'Captcha-Code': loginForm.code,
  140. 'Tenant-Id': loginForm.tenantId,
  141. 'Authorization':'Basic c2FiZXI6c2FiZXJfc2VjcmV0',
  142. 'Blade-Auth': undefined
  143. },
  144. success: res => {
  145. if(res.statusCode == 200){
  146. this.$storage.setStorageSync('token', res.data.access_token)
  147. this.$storage.setStorageSync('userInfo', res.data)
  148. this.$utils.openNew('/pages/index/index')
  149. }
  150. console.log(res)
  151. },
  152. });
  153. // this.$http.Login(this.form).then(res => {
  154. // console.log(res)
  155. // if (res.code === 0) {
  156. // this.$storage.setStorageSync('token', res.result.token)
  157. // this.saveUserInfo()
  158. // }
  159. // })
  160. })
  161. },
  162. // 获取并保存用户信息到本地
  163. saveUserInfo() {
  164. this.$http.GetUserInfo().then(res => {
  165. console.log(res)
  166. if (res.code == 0) {
  167. this.setUserInfo(res.result)
  168. this.$storage.setStorageSync('userInfo', res.result)
  169. this.$utils.openNew('/pages/index/index')
  170. }
  171. })
  172. },
  173. checkboxGroupChange() {},
  174. toggleForget() {}
  175. },
  176. onLoad() {
  177. this.form.account = this.userInfo.account
  178. this.$utils.updateVersion()
  179. },
  180. onReady() {
  181. this.$refs.uForm.setRules(this.rules);
  182. },
  183. computed: {
  184. // 测试环境下显示ip输入
  185. isDev() {
  186. if (process.env.NODE_ENV === 'development') {
  187. return true
  188. } else {
  189. return false
  190. }
  191. }
  192. }
  193. }
  194. </script>
  195. <style lang="scss" scoped>
  196. @import '../../static/css/mycss.scss';
  197. @import '../../static/css/animate.css';
  198. /deep/ .u-select__body__picker-view__item {
  199. .u-line-1 {
  200. font-size: 46rpx;
  201. }
  202. }
  203. /deep/ .u-select__header__btn {
  204. font-size: 46rpx;
  205. }
  206. /deep/ .u-drawer-content {
  207. border-radius: 20rpx 20rpx 0 0;
  208. }
  209. .container-wrap {
  210. width: 750rpx;
  211. .container {
  212. height: calc(100vh - var(--status-bar-height));
  213. .form-wrap {
  214. position: relative;
  215. width: 620rpx;
  216. height: 85vh;
  217. border-radius: 20rpx;
  218. background: #FFFFFF;
  219. box-shadow: 0 5px 10px #383838;
  220. .logo-wrap {
  221. flex: 1;
  222. width: 100%;
  223. .logo {
  224. width: 250rpx;
  225. min-width: 250rpx;
  226. height: 100rpx;
  227. }
  228. }
  229. .form {
  230. flex: 1;
  231. padding: 0 50rpx;
  232. width: 100%;
  233. .forget {
  234. position: absolute;
  235. bottom: -30rpx;
  236. right: 0;
  237. color: #666666;
  238. }
  239. }
  240. .bottom-pic-wrap {
  241. flex: 1;
  242. width: 100%;
  243. .bottom-pic {
  244. height: 80%;
  245. min-height: 250rpx;
  246. // width: 311rpx;
  247. // height: 315rpx;
  248. }
  249. }
  250. }
  251. .forget-wrap {
  252. position: relative;
  253. width: 580rpx;
  254. height: 620rpx;
  255. box-shadow: 0 5px 10px #383838;
  256. border-radius: 20rpx;
  257. background: #fff;
  258. .close-icon-wrap {
  259. position: absolute;
  260. top: 18rpx;
  261. right: 18rpx;
  262. .close-icon {
  263. width: 50rpx;
  264. height: 50rpx;
  265. }
  266. }
  267. .gantanhao-wrap {
  268. padding-top: 120rpx;
  269. .gantanhao {
  270. width: 200rpx;
  271. height: 160rpx;
  272. }
  273. }
  274. .text {
  275. padding-top: 75rpx;
  276. text-align: center;
  277. color: #333;
  278. .phone {
  279. color: rgb(200, 60, 160);
  280. font-weight: bold;
  281. }
  282. }
  283. }
  284. }
  285. .version {
  286. position: fixed;
  287. bottom: 0;
  288. left: 0;
  289. width: 100%;
  290. padding: 10rpx 0;
  291. text-align: center;
  292. }
  293. }
  294. </style>