login.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <template>
  2. <view class="login">
  3. <view class="title">GoEasy IM</view>
  4. <view class="user-selector">
  5. <view class="selected-area" @click="switchSelectorVisible">
  6. <view class="selected-content" v-if="userSelector.selectedUser">
  7. <image :src="userSelector.selectedUser.avatar"></image>
  8. <text>{{ userSelector.selectedUser.name }}</text>
  9. </view>
  10. <view class="selected-content" v-else>
  11. <text>请选择用户</text>
  12. </view>
  13. <image class="selected-icon rotate" src="/static/images/up.png"></image>
  14. </view>
  15. <view v-if="userSelector.visible" class="dialog-area">
  16. <view class="dialog-list">
  17. <view class="dialog-list-item" v-for="(user, index) in userSelector.users" :key="index" @click="selectUser(user)">
  18. <image class="dialog-list-item-avatar" :src="user.avatar"></image>
  19. <text>{{ user.name }}</text>
  20. </view>
  21. </view>
  22. </view>
  23. </view>
  24. <view class="password-box">
  25. <input v-model="form.phone" class="password-input" placeholder="请输入账号" type="text">
  26. </view>
  27. <view class="password-box">
  28. <input v-model="form.password" class="password-input" placeholder="请输入密码" :password="!password.visible" type="text">
  29. <image class="password-image" @click="switchPasswordVisible" src="/static/images/visible.png"></image>
  30. </view>
  31. <view v-show="errorVisible" class="alert-box">
  32. <image src="/static/images/login-alert-icon.png"></image>
  33. <span>请输入正确的用户名和密码</span>
  34. </view>
  35. <button class="login-btn" @click="login">登录</button>
  36. <view class="version">{{ versionName }}</view>
  37. </view>
  38. </template>
  39. <script>
  40. import restApi from '../lib/restapi';
  41. const {versionName} = require('../manifest.json');
  42. export default {
  43. name: 'Login',
  44. data() {
  45. return {
  46. versionName: versionName,
  47. userSelector: {
  48. users: [],
  49. visible: false,
  50. selectedUser: null
  51. },
  52. username: '',
  53. password: {
  54. visible: false,
  55. value: '123'
  56. },
  57. form:{
  58. password:'',
  59. phone:'',
  60. },
  61. errorVisible: false
  62. }
  63. },
  64. onLoad() {
  65. this.userSelector.users = restApi.findUsers();
  66. },
  67. methods: {
  68. switchSelectorVisible() {
  69. this.userSelector.visible = !this.userSelector.visible;
  70. },
  71. selectUser(user) {
  72. this.userSelector.visible = false;
  73. this.userSelector.selectedUser = user;
  74. this.username = user.name;
  75. },
  76. switchPasswordVisible() {
  77. this.password.visible = !this.password.visible;
  78. },
  79. login() {
  80. var that=this;
  81. var obj={
  82. name:'',
  83. id:'',
  84. email:'',
  85. avatar:'',
  86. password:'',
  87. phone:'',
  88. }
  89. this.$http('imSys/imLoginTmp', {
  90. userCode:this.form.phone,
  91. userPwd:this.form.password,
  92. },'POST').then(res => {
  93. console.log(res)
  94. obj.name=res.data.supplierName
  95. obj.id=res.data.userId
  96. obj.password=this.form.password
  97. obj.phone=this.form.phone
  98. uni.setStorageSync('currentUser', obj);
  99. uni.setStorageSync('imAccessToken', res.data.imAccessToken);
  100. uni.switchTab({url: './conversations'});
  101. })
  102. /* if (this.username.trim() !== '' && this.password.value.trim() !== '') {
  103. let user = restApi.findUser(this.username, this.password.value);
  104. if (user) {
  105. uni.setStorageSync('currentUser', user);
  106. uni.switchTab({url: './conversations'});
  107. return
  108. }
  109. } */
  110. // this.errorVisible = true;
  111. }
  112. }
  113. }
  114. </script>
  115. <style>
  116. .login {
  117. width: 100%;
  118. height: 100%;
  119. display: flex;
  120. flex-direction: column;
  121. align-items: center;
  122. }
  123. .title {
  124. padding-top: 160rpx;
  125. height: 100rpx;
  126. font-size: 60rpx;
  127. text-align: center;
  128. font-style: normal;
  129. font-weight: normal;
  130. color: #d02129;
  131. margin-bottom: 80rpx;
  132. }
  133. .alert-box {
  134. width: 640rpx;
  135. height: 60rpx;
  136. margin-bottom: 60rpx;
  137. padding: 0rpx 20rpx;
  138. font-size: 34rpx;
  139. line-height: 48rpx;
  140. display: flex;
  141. align-content: center;
  142. overflow: hidden;
  143. color: #EE593C;
  144. align-items: center;
  145. }
  146. .alert-box image {
  147. width: 30rpx;
  148. height: 30rpx;
  149. margin-right: 20rpx;
  150. }
  151. .login-btn {
  152. width: 680rpx;
  153. height: 100rpx;
  154. line-height: 100rpx;
  155. font-size: 36rpx;
  156. text-align: center;
  157. color: #ffffff;
  158. background: #d02129;
  159. outline: none;
  160. border: 0;
  161. }
  162. .password-box {
  163. position: relative;
  164. }
  165. .password-input {
  166. width: 620rpx;
  167. padding: 28rpx;
  168. border: 1px solid #cccccc;
  169. margin-bottom: 40rpx;
  170. font-size: 34rpx;
  171. }
  172. .password-image {
  173. width: 50rpx;
  174. height: 50rpx;
  175. position: absolute;
  176. top: 28rpx;
  177. right: 28rpx;
  178. }
  179. .user-selector {
  180. width: 700rpx;
  181. margin-bottom: 40rpx;
  182. }
  183. .selected-area {
  184. display: flex;
  185. flex-direction: row;
  186. align-items: center;
  187. width: 620rpx;
  188. height: 100rpx;
  189. border: 1px solid #cccccc;
  190. margin: 0 auto;
  191. padding: 0 28rpx;
  192. }
  193. .selected-content {
  194. display: flex;
  195. align-items: center;
  196. flex-grow: 1;
  197. }
  198. .selected-content image {
  199. width: 80rpx;
  200. height: 80rpx;
  201. margin-right: 30rpx;
  202. border-radius: 50%;
  203. }
  204. .selected-icon {
  205. width: 40rpx;
  206. height: 40rpx;
  207. margin-right: 10rpx;
  208. }
  209. .selected-icon.rotate {
  210. transform-origin: center;
  211. transform: rotate(180deg);
  212. }
  213. .dialog-area {
  214. position: absolute;
  215. width: 100%;
  216. background: #E5E5E5;
  217. }
  218. .dialog-list {
  219. position: absolute;
  220. left: 10rpx;
  221. top: 8rpx;
  222. width: 674rpx;
  223. border: 1px solid #cccccc;
  224. background: #ffffff;
  225. box-shadow: 8rpx 8rpx 10rpx #e1e1e1;
  226. padding: 30rpx 0;
  227. z-index: 99;
  228. }
  229. .dialog-list-item {
  230. width: 100%;
  231. margin: 25rpx 0;
  232. padding-left: 40rpx;
  233. display: flex;
  234. align-items: center;
  235. }
  236. .dialog-list-item-avatar {
  237. width: 80rpx;
  238. height: 80rpx;
  239. margin-right: 30rpx;
  240. border-radius: 50%;
  241. }
  242. .version {
  243. color: #ffffff;
  244. font-size: 40rpx;
  245. margin-top: 60rpx;
  246. }
  247. view {
  248. user-select: text;
  249. }
  250. </style>