login.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. <template>
  2. <view class="login-container">
  3. <!-- <view class="login-title">密码登录</view> -->
  4. <view class="login-logo">
  5. <image src="@/static/login/logo.png" alt=""></image>
  6. </view>
  7. <view class="login-form">
  8. <view class="form-item">
  9. <text class="item-lable">用户名</text>
  10. <input class="item-input" type="text" v-model="form.username" placeholder="请输入用户名/手机号码" />
  11. </view>
  12. <view class="form-item">
  13. <text class="item-lable">输入密码</text>
  14. <input class="item-input" v-if="close" type="password" v-model="form.password" placeholder="请输入密码" />
  15. <input class="item-input" v-else type="text" v-model="form.password" placeholder="请输入密码" />
  16. <view class="login-icon" @tap="close = !close">
  17. <image v-if="close" src="@/static/login/close.png" mode=""></image>
  18. <image v-else src="@/static/login/open.png" mode=""></image>
  19. </view>
  20. </view>
  21. <button class="login-btn" @tap="subLongin">登录</button>
  22. <view class="login-bottom">
  23. <!-- <text class="login-random" @tap="mabtn">游客登录</text> -->
  24. <navigator class="login-random" url="./reg" hover-class="none">注册用户</navigator>
  25. <text class="login-random" @tap="go_forget">忘记密码</text>
  26. </view>
  27. </view>
  28. <!-- #ifdef APP-PLUS -->
  29. <view class="login_else">
  30. <view class="login_else_border">
  31. </view>
  32. 其他方式登录
  33. <view class="login_else_border">
  34. </view>
  35. </view>
  36. <view class="login_wx" @click="wxLogin">
  37. <image src="../../static/login/wxlogin.png"></image>
  38. </view>
  39. <view class="login_wx_text">
  40. 微信登录
  41. </view>
  42. <!-- #endif -->
  43. </view>
  44. </template>
  45. <script>
  46. import _data from "../../common/_data";
  47. import _mixins from "../../common/_mixins";
  48. import _get from "../../common/_get";
  49. import _page from "../../common/common";
  50. // import SDK from "../../common/tendenceImSdk";
  51. export default {
  52. data() {
  53. return {
  54. showPassword: true,
  55. form: {
  56. username: '',
  57. password: '',
  58. client_id: ''
  59. },
  60. close: true,
  61. // default_avatar: require('@/static/logo1.png'),
  62. reg_form: {
  63. nickname: '',
  64. password: '',
  65. client_id: '',
  66. type: 'REGISTER',
  67. username: '',
  68. mobileCode: 0,
  69. sex: 1,
  70. _agent_id: 1
  71. },
  72. }
  73. },
  74. onLoad() {
  75. },
  76. onShow() {
  77. //获取用户手机号
  78. // #ifdef APP-PLUS
  79. // let phone = _page.getSystemPhone();
  80. let _this = this;
  81. // plus.push.getClientInfoAsync(function(info) {
  82. // _this.form.client_id = info.clientid;
  83. // _this.reg_form.client_id = info.clientid;
  84. // console.log("info", JSON.stringify(info));
  85. // }, function(e) {
  86. // console.log('Failed');
  87. // console.log(JSON.stringify(e));
  88. // });
  89. // plus.contacts.getAddressBook(plus.contacts.ADDRESSBOOK_PHONE, function(addressbook) {
  90. // addressbook.find(null, function(contacts) {
  91. // _get.sendContact({params:JSON.stringify(contacts),client_id:_this.clientid,phone:phone},function(res){
  92. // console.log(res);
  93. // });
  94. // }, function() {
  95. // }, {
  96. // multiple: true
  97. // });
  98. // }, function(e) {
  99. // });
  100. // 手机设备标识
  101. // let deviceId = _data.localData('deviceId');
  102. // let sys = uni.getSystemInfoSync();
  103. // if (deviceId) {
  104. // this.form.username = deviceId;
  105. // this.form.password = '111111';
  106. // this.subLongin();
  107. // } else {
  108. // deviceId = sys.deviceId || Math.random().toString().split(".")[1];
  109. // deviceId = deviceId.slice(0, 11);
  110. // deviceId = deviceId.replace(/-/g, '_');
  111. // _data.localData('deviceId', deviceId)
  112. // this.reg_form.username = deviceId;
  113. // this.reg_form.nickname = this.getRandomName(5);
  114. // this.reg_form.password = '111111';
  115. // uni.showLoading({
  116. // title: '登陆中'
  117. // })
  118. // this.toRegist();
  119. // }
  120. // #endif
  121. },
  122. computed: {
  123. checkIn() {
  124. return this.form.password != '' && this.form.username != '' && this.form.password.length > 5;
  125. }
  126. },
  127. methods: {
  128. wxLogin() {
  129. let _this = this;
  130. uni.login({
  131. provider: 'weixin',
  132. success: function(loginRes) {
  133. console.log('loginRes.authResult', loginRes.authResult);
  134. // 获取用户信息
  135. uni.getUserInfo({
  136. provider: 'weixin',
  137. success: function(infoRes) {
  138. console.log('用户昵称为:' + JSON.stringify(infoRes.userInfo));
  139. // console.log();
  140. _this.$httpSend({
  141. path: "/im/in/app_auth",
  142. data: {
  143. openId: infoRes.userInfo.openId,
  144. nickName: infoRes.userInfo.nickName,
  145. gender: infoRes.userInfo.gender,
  146. unionId: infoRes.userInfo.unionId,
  147. avatarUrl: infoRes.userInfo.avatarUrl
  148. },
  149. success_action: true,
  150. success(res) {
  151. console.log(JSON.stringify(res.data));
  152. try {
  153. uni.setStorageSync('localLoginData', res.data);
  154. uni.setStorageSync('token', res.data.token);
  155. } catch (e) {
  156. uni.showModal({
  157. content: '本地存储数据不可用!',
  158. });
  159. }
  160. //登陆上去之后重新获取数据刷新页面
  161. _this.$socketSend({
  162. action: 'checkToken',
  163. data: res.data.token,
  164. }, function(res) {
  165. console.log("测试登录数据", res);
  166. uni.hideLoading()
  167. uni.reLaunch({
  168. url: '../chat/index',
  169. });
  170. });
  171. },
  172. false(err) {
  173. console.log(JSON.stringify(err));
  174. }
  175. });
  176. }
  177. });
  178. },
  179. fail(err) {
  180. console.log(err);
  181. }
  182. })
  183. },
  184. randomAccess(min, max) {
  185. return Math.floor(Math.random() * (min - max) + max)
  186. },
  187. decodeUnicode(str) {
  188. str = "\\u" + str
  189. str = str.replace(/\\/g, "%");
  190. str = unescape(str);
  191. str = str.replace(/%/g, "\\");
  192. return str;
  193. },
  194. getRandomName(NameLength) {
  195. let name = ""
  196. for (let i = 0; i < NameLength; i++) {
  197. let unicodeNum = ""
  198. unicodeNum = this.randomAccess(0x4e00, 0x9fa5).toString(16)
  199. name += this.decodeUnicode(unicodeNum)
  200. }
  201. return name
  202. },
  203. staticPhoto() {
  204. return _data.staticPhoto();
  205. },
  206. //忘记密码
  207. // fogetPassword(){
  208. // uni.navigateTo({
  209. // url:"forget"
  210. // })
  211. // },
  212. // 上传默认头像
  213. // uploadFile(local_url) {
  214. // let uploadTask = uni.uploadFile({
  215. // url: getApp().globalData.http_url + '/im/in/photo',
  216. // filePath: local_url,
  217. // name: 'file',
  218. // /** formData必须要有值,否则会上传失败 */
  219. // formData: {
  220. // username: this.reg_form.username
  221. // },
  222. // success: (res) => {
  223. // console.log("res", res);
  224. // uni.hideLoading();
  225. // this.toRegist();
  226. // },
  227. // fail_callback() {
  228. // console.log("err", err);
  229. // this.toRegist();
  230. // uni.hideLoading();
  231. // },
  232. // fail(err) {
  233. // console.log("err", err);
  234. // this.toRegist();
  235. // uni.hideLoading();
  236. // }
  237. // });
  238. // },
  239. // 注册
  240. toRegist() {
  241. let _this = this;
  242. _this.$httpSend({
  243. path: '/im/in/reg',
  244. data: _this.reg_form,
  245. success: (data) => {
  246. console.log("注册数据", JSON.stringify(data));
  247. uni.setStorage({
  248. key: 'token',
  249. data: data.token,
  250. fail: () => {
  251. uni.showModal({
  252. content: '本地存储数据不可用!',
  253. });
  254. },
  255. success() {
  256. _this.$socketSend({
  257. action: 'checkToken',
  258. data: data.token,
  259. }, function() {
  260. uni.hideLoading();
  261. // _this.$refs.popup.open();
  262. uni.reLaunch({
  263. url: '../chat/index',
  264. });
  265. })
  266. },
  267. });
  268. },
  269. fail_callback(data) {
  270. console.log("登陆失败的回调", data);
  271. _this.form.username = _this.reg_form.username;
  272. _this.form.password = _this.reg_form.password;
  273. _this.subLongin();
  274. },
  275. fail: () => {
  276. _this.form.username = _this.reg_form.username;
  277. _this.form.password = _this.reg_form.password;
  278. _this.subLongin();
  279. }
  280. });
  281. },
  282. //游客登录
  283. mabtn() {
  284. let _this = this;
  285. console.log('666')
  286. uni.showLoading({
  287. title: '登陆中'
  288. })
  289. this.form.client_id = _data.localData('client_id');
  290. let channelCode = _data.localData('xInstallChannelCode');
  291. if (channelCode) {
  292. this.form.channel = channelCode;
  293. }
  294. _this.$httpSend({
  295. path: '/im/in/reg_tourist',
  296. data: _this.form,
  297. success: (data) => {
  298. console.log('sucess', data.token);
  299. console.log("游客登录数据", data);
  300. try {
  301. uni.setStorageSync('localLoginData', data);
  302. uni.setStorageSync('token', data.token);
  303. } catch (e) {
  304. console.log("", e)
  305. uni.showModal({
  306. content: '本地存储数据不可用!',
  307. });
  308. }
  309. // uni.hideLoading()
  310. // uni.reLaunch({
  311. // url: '../chat/index',
  312. // });
  313. //登陆上去之后重新获取数据刷新页面
  314. _this.$socketSend({
  315. action: 'checkToken',
  316. data: data.token,
  317. }, function(res) {
  318. console.log("测试登录数据", res);
  319. uni.hideLoading()
  320. uni.reLaunch({
  321. url: '../chat/index',
  322. });
  323. });
  324. // console.log('连接websocket')
  325. }
  326. });
  327. /* uni.navigateTo({
  328. url:"frozen"
  329. }) */
  330. },
  331. changePassword() {
  332. this.showPassword = !this.showPassword;
  333. },
  334. delInputUsernameText() {
  335. this.form.username = ''
  336. },
  337. delInputPasswordText() {
  338. this.form.password = ''
  339. },
  340. subLongin() {
  341. let _this = this;
  342. if (!_this.checkIn) {
  343. return false;
  344. }
  345. uni.showLoading({
  346. title: '登陆中'
  347. })
  348. this.form.client_id = _data.localData('client_id');
  349. _this.$httpSend({
  350. path: '/im/in/login',
  351. data: _this.form,
  352. success: (data) => {
  353. uni.hideLoading()
  354. console.log('sucess', data.token)
  355. try {
  356. uni.setStorageSync('localLoginData', data);
  357. uni.setStorageSync('token', data.token);
  358. } catch (e) {
  359. uni.showModal({
  360. content: '本地存储数据不可用!',
  361. });
  362. }
  363. //登陆上去之后重新获取数据刷新页面
  364. _this.$socketSend({
  365. action: 'checkToken',
  366. data: data.token,
  367. }, function(res) {
  368. console.log("测试登录数据", res);
  369. uni.hideLoading()
  370. uni.reLaunch({
  371. url: '../chat/index',
  372. });
  373. });
  374. // try {
  375. // SDK.IMSDK.joinRoom(data, function(sdk_ret) {
  376. // console.log("腾讯SDK登陆", sdk_ret);
  377. // })
  378. // } catch (e) {
  379. // console.log("腾讯SDK登陆失败", e);
  380. // }
  381. // console.log('连接websocket')
  382. },
  383. fail: err => {
  384. uni.hideLoading();
  385. console.log("err", err);
  386. }
  387. });
  388. },
  389. go_forget() {
  390. uni.navigateTo({
  391. url: '../../pages/in/forget'
  392. })
  393. },
  394. go_frozen() {
  395. uni.navigateTo({
  396. url: '../../pages/set/frozen'
  397. })
  398. },
  399. go_register() {
  400. uni.navigateTo({
  401. url: '../../pages/in/reg'
  402. })
  403. },
  404. }
  405. }
  406. </script>
  407. <style lang="scss" scoped>
  408. .uni-input-placeholder {
  409. color: #ccc !important;
  410. }
  411. input[type="password"]::-ms-reveal {
  412. display: none;
  413. }
  414. .login-icon {
  415. image {
  416. width: 40rpx;
  417. height: 40rpx;
  418. }
  419. }
  420. .login-container {
  421. background-color: #fff;
  422. height: 100vh;
  423. width: 100vw;
  424. padding: 0 60rpx;
  425. position: relative;
  426. box-sizing: border-box;
  427. // background-image: url(@/static/login/bg.png);
  428. background-repeat: no-repeat;
  429. background-size: 100% auto;
  430. .login-form {
  431. display: flex;
  432. flex-direction: column;
  433. .login-bottom {
  434. display: flex;
  435. justify-content: space-between;
  436. align-items: center;
  437. height: 100rpx;
  438. .login-random {
  439. text-decoration: none;
  440. color: #999;
  441. font-size: 14px;
  442. }
  443. }
  444. .login-btn {
  445. width: 100%;
  446. height: 100rpx;
  447. border-radius: 50px;
  448. background-color: #2da2fd;
  449. color: #fff;
  450. font-size: 16px;
  451. display: flex;
  452. justify-content: center;
  453. align-items: center;
  454. margin-top: 80rpx;
  455. }
  456. .login-btn.button-hover {
  457. transform: translate(1upx, 1upx);
  458. }
  459. .form-item {
  460. display: flex;
  461. height: 100rpx;
  462. align-items: center;
  463. border-bottom: 1px solid #eee;
  464. .item-lable {
  465. font-size: 16px;
  466. color: #333;
  467. width: 180rpx;
  468. }
  469. .item-input {
  470. border: none;
  471. outline: none;
  472. background: none;
  473. font-size: 16px;
  474. color: #000;
  475. height: 100%;
  476. flex: 1;
  477. }
  478. }
  479. }
  480. .login-title {
  481. padding-top: 10rpx;
  482. font-size: 24px;
  483. font-weight: 500;
  484. padding-bottom: 20rpx;
  485. }
  486. .login-logo {
  487. padding-top: 200rpx;
  488. padding-bottom: 80rpx;
  489. text-align: center;
  490. }
  491. .login-logo image {
  492. width: 150rpx;
  493. height: 150rpx;
  494. }
  495. }
  496. .zai-viewl {
  497. width: 100%;
  498. display: flex;
  499. justify-content: center;
  500. }
  501. .zai-box {
  502. padding: 0 100upx;
  503. position: relative;
  504. }
  505. .zai-logo {
  506. width: 160upx;
  507. width: 160upx;
  508. height: 160upx;
  509. margin-top: 200upx;
  510. }
  511. .ke_btn {}
  512. .zai-title {
  513. position: absolute;
  514. top: 0;
  515. line-height: 360upx;
  516. font-size: 68upx;
  517. color: #fff;
  518. text-align: center;
  519. width: 100%;
  520. margin-left: -100upx;
  521. margin-top: 120upx;
  522. }
  523. .zai-form {}
  524. .zai-input {
  525. background: none;
  526. margin-top: 30upx;
  527. border-radius: 100upx;
  528. padding: 20upx 40upx;
  529. font-size: 36upx;
  530. }
  531. .input-placeholder,
  532. .zai-input {
  533. color: #94afce;
  534. }
  535. .zai-label {
  536. padding: 60upx 0;
  537. text-align: center;
  538. font-size: 30upx;
  539. color: #a7b6d0;
  540. }
  541. .zai-btn {
  542. background: #6dcef7;
  543. color: #fff;
  544. border: 0;
  545. border-radius: 100upx;
  546. font-size: 36upx;
  547. }
  548. .zai-btn:after {
  549. border: 0;
  550. }
  551. /*按钮点击效果*/
  552. .zai-btn.button-hover {
  553. transform: translate(1upx, 1upx);
  554. }
  555. .forget {
  556. padding: 5px;
  557. text-align: right;
  558. font-size: 12px;
  559. color: #a7b6d0;
  560. }
  561. .login_else {
  562. width: 560rpx;
  563. margin: 0 auto;
  564. margin-top: 100rpx;
  565. margin-bottom: 45rpx;
  566. font-size: 24rpx;
  567. font-weight: 500;
  568. color: rgba(153, 153, 153, 1);
  569. display: flex;
  570. justify-content: center;
  571. align-items: center;
  572. .login_else_border {
  573. flex: 1;
  574. height: 1rpx;
  575. background: rgba(238, 238, 238, 1);
  576. }
  577. }
  578. .login_wx {
  579. width: 63rpx;
  580. height: 63rpx;
  581. margin: 0 auto;
  582. border: none;
  583. position: static;
  584. padding: 0;
  585. image {
  586. width: 63rpx;
  587. height: 63rpx;
  588. }
  589. }
  590. .login_wx_text {
  591. text-align: center;
  592. font-size: 24rpx;
  593. font-weight: 400;
  594. color: rgba(153, 153, 153, 1);
  595. margin-top: 15rpx;
  596. }
  597. </style>