login.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <template>
  2. <view class="nv-login">
  3. <image class="img1" src="../../static/loginBg.png" mode=""></image>
  4. <view class="nv-position">
  5. <view class="nv-header">
  6. <image class="logo" src="../../static/logo.png" mode=""></image>
  7. </view>
  8. <view class="nv-center" elevation="5px">
  9. <view class="title">
  10. <text class="text">巡检机器人手机客户端</text>
  11. </view>
  12. <view class="n-input">
  13. <uni-easyinput prefixIcon="icon-ren" @blur="inputStyles1.borderColor = '#DCDCDC'"
  14. @focus="inputStyles1.borderColor = '#2B85E0'" :styles="inputStyles1" :disabled="loading"
  15. custom-prefix="iconfont" v-model="user.account" placeholder="请输入账号/手机号"></uni-easyinput>
  16. </view>
  17. <view class="n-input">
  18. <uni-easyinput type="password" prefixIcon="icon-mima1" @blur="inputStyles2.borderColor = '#DCDCDC'"
  19. @focus="inputStyles2.borderColor = '#2B85E0'" :styles="inputStyles2" :disabled="loading"
  20. custom-prefix="iconfont" v-model="user.password" placeholder="请输入密码"></uni-easyinput>
  21. </view>
  22. <checkbox-group class="checkbox" @change="changeValue">
  23. <checkbox style="transform: scale(0.7);margin-left: auto;" :value="1" :checked="checked" />记住密码
  24. </checkbox-group>
  25. <button elevation="3px" class="nv-but" type="primary" :disabled="loading" :loading="loading"
  26. @click="login">登录</button>
  27. <view class="nv-server" @click="changeConfig">服务代理设置</view>
  28. </view>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. import {
  34. getToken,
  35. getUser
  36. } from '../../common/api.js'
  37. import {
  38. getAuthsArr,
  39. BeforeNavigateTo
  40. } from '../../common/utils.js'
  41. import {
  42. Encrypt
  43. } from '@/common/aes.js';
  44. import {api_config} from '@/config.js'
  45. export default {
  46. data() {
  47. return {
  48. checked:false,
  49. inputStyles1: {
  50. color: '#222',
  51. borderColor: '#DCDCDC'
  52. },
  53. inputStyles2: {
  54. color: '#222',
  55. borderColor: '#DCDCDC'
  56. },
  57. user: {
  58. account: "",
  59. password: null,
  60. methodName: "login",
  61. "timestamp": new Date()
  62. },
  63. loading: false,
  64. activeIndex: 0,
  65. width: 120,
  66. height: 45,
  67. keys: {},
  68. code: '',
  69. codeKey: '',
  70. clientInfo: ''
  71. }
  72. },
  73. mounted() {
  74. },
  75. onShow() {
  76. this.clientInfo = plus.push.getClientInfo().clientid
  77. if(uni.getStorageSync('XJAPP-PASSWORD')){
  78. this.user = uni.getStorageSync('XJAPP-PASSWORD')
  79. this.checked = true
  80. }
  81. },
  82. methods: {
  83. changeConfig() {console.log(1234)
  84. uni.navigateTo({
  85. animationType: 'pop-in',
  86. animationDuration: 300,
  87. url: '../../pages/webview/changeConfig',
  88. })
  89. },
  90. changeValue(e){
  91. if(e.target.value && e.target.value[0]){
  92. this.checked = true
  93. }
  94. else{
  95. this.checked = false
  96. }
  97. },
  98. async login() {
  99. if (!this.user.account) {
  100. uni.showToast({
  101. icon: 'none',
  102. title: '账号/手机号不能为空',
  103. duration: 2000
  104. });
  105. return false
  106. }
  107. if (!this.user.password) {
  108. uni.showToast({
  109. icon: 'none',
  110. title: '密码不能为空',
  111. duration: 2000
  112. });
  113. return false
  114. }
  115. if (this.loading) return
  116. this.loading = true
  117. let params = {
  118. ...this.user,
  119. // password: Encrypt(this.user.password, this.keys.tokenKey),
  120. }
  121. /* export function getToken(data) { //登录接口
  122. return new RequestFun().fetch(
  123. '/app/user/loginApp',
  124. 'POST',
  125. data
  126. )
  127. }
  128. export function getUser(data) { //查看个人信息
  129. return new RequestFun().fetch(
  130. `/app/user/getUserInfo`,
  131. 'GET',
  132. data
  133. )
  134. }*/
  135. /*var sseverUrl = "http://"+uni.getStorageSync("xjappserver").url+':'+uni.getStorageSync("xjappserver").port
  136. uni.request({
  137. url: sseverUrl+'/app/user/loginApp', //仅为示例,并非真实接口地址。
  138. data: params,
  139. header: {
  140. appId: uni.getStorageSync('storage_users').uid,
  141. authorization: uni.getStorageSync('storage_token')
  142. },
  143. method: "POST",
  144. success: (res) => {
  145. console.log(111111);
  146. console.log(res);
  147. this.$store.dispatch("setToken", res.data.data.userId)
  148. this.checked ? uni.setStorageSync('XJAPP-PASSWORD', {
  149. ...this.user
  150. }) : uni.removeStorageSync('XJAPP-PASSWORD')
  151. uni.request({
  152. url: sseverUrl+'/app/user/getUserInfo', //仅为示例,并非真实接口地址。
  153. data: {
  154. userId:res.data.data.userId
  155. },
  156. header: {
  157. appId: uni.getStorageSync('storage_users').uid,
  158. authorization: uni.getStorageSync('storage_token')
  159. },
  160. method: "GET",
  161. success: (response) => {
  162. console.log(222222);
  163. console.log(response);
  164. this.$store.dispatch("setUsers",response.data.data)
  165. this.loading = false
  166. uni.switchTab({
  167. url: "/pages/native/work"
  168. });
  169. }
  170. })
  171. },
  172. fail: (e) => {console.log(e)
  173. this.loading = false
  174. plus.nativeUI.toast("无法连接服务器,请检查服务代理设置")
  175. }
  176. })*/
  177. getToken(params).then(res => {
  178. this.$store.dispatch("setToken", res.userId)
  179. this.checked ? uni.setStorageSync('XJAPP-PASSWORD', {
  180. ...this.user
  181. }) : uni.removeStorageSync('XJAPP-PASSWORD')
  182. getUser({
  183. userId:res.userId
  184. }).then(response => {
  185. uni.setStorageSync("getRealNews",response.msgStatus)
  186. this.$store.dispatch("setUsers",response)
  187. this.loading = false
  188. uni.switchTab({
  189. url: "/pages/native/work"
  190. });
  191. }).catch(e => {
  192. this.loading = false
  193. })
  194. }).catch(e => {
  195. plus.nativeUI.toast(e.data.msg)
  196. this.loading = false
  197. console.log(e)
  198. })
  199. this.loading = false
  200. }
  201. }
  202. }
  203. </script>
  204. <style scoped lang="scss">
  205. .canvas-img-code {
  206. display: inline-block;
  207. }
  208. .nv-login {
  209. background: #fff;
  210. .img1 {
  211. height: 691rpx;
  212. width: 750rpx;
  213. }
  214. .nv-position {
  215. position: absolute;
  216. top: 220rpx;
  217. left: 20rpx;
  218. right: 20rpx;
  219. z-index: 999;
  220. }
  221. .nv-header {
  222. display: flex;
  223. flex-direction: column;
  224. justify-content: center;
  225. align-items: center;
  226. .logo {
  227. width: 180rpx;
  228. height: 180rpx;
  229. }
  230. }
  231. .nv-center {
  232. margin-top: 120rpx;
  233. background-color: #fff;
  234. border-radius: 50rpx;
  235. padding: 58rpx 0rpx;
  236. margin-bottom: 30rpx;
  237. margin-left: 20rpx;
  238. margin-right: 20rpx;
  239. box-shadow: #ccc 0 0 10px;
  240. .title {
  241. text-align: center;
  242. border-bottom: 1px solid #EFEFF4;
  243. padding-bottom: 64rpx;
  244. .text {
  245. font-size: 42rpx;
  246. color: #000000;
  247. font-weight: bold;
  248. }
  249. }
  250. .nv-but {
  251. height: 88rpx;
  252. line-height: 88rpx;
  253. background: #0581FD;
  254. border-radius: 16rpx;
  255. font-weight: bold;
  256. font-size: 38rpx;
  257. box-shadow: #BBBBBB 0 0 10px;
  258. margin: 30rpx 40rpx 20rpx 40rpx;
  259. }
  260. .nv-server{
  261. margin-bottom: 110rpx;
  262. margin-right: 40rpx;
  263. text-align: right;
  264. color: #0581FD;
  265. }
  266. .checkbox{
  267. margin: 20rpx 42rpx 0 42rpx;
  268. display: flex;
  269. align-items: center;
  270. font-size: 24rpx;
  271. }
  272. .n-input {
  273. font-size: 34rpx;
  274. margin: 60rpx 42rpx 0 42rpx;
  275. .t3 {
  276. font-size: 26rpx;
  277. color: #999999;
  278. }
  279. .input1 {
  280. font-size: 34rpx;
  281. height: 74rpx;
  282. }
  283. }
  284. }
  285. }
  286. </style>