index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. <template>
  2. <view class="content" :style="colorStyle">
  3. <view class="tit">
  4. 轻触头像以切换帐号
  5. </view>
  6. <!-- 当前账号 -->
  7. <view class="account-wrap">
  8. <image :src="'../../../static/images/f.png'" mode="" class="u-logo"></image>
  9. <view class="u-info">
  10. <view class="info-name">
  11. {{userInfo.phone}}
  12. </view>
  13. <!-- <view class="info-id">
  14. UID:{{userInfo.uid}}
  15. </view> -->
  16. </view>
  17. <view class="set">
  18. <view class="new-use">
  19. <text></text>当前使用
  20. </view>
  21. </view>
  22. </view>
  23. <!-- 账号列表 -->
  24. <template v-for="(item,index) in menList">
  25. <view class="account-wrap" v-if="item.account != userInfo.phone">
  26. <image v-if="item.avatar" :src="item.avatar" mode="" class="u-logo" @click="login(item)"></image>
  27. <image v-else src="../../../static/images/f.png" mode="" class="u-logo" @click="login(item)"></image>
  28. <view class="u-info">
  29. <view class="info-name">
  30. {{item.account}}
  31. </view>
  32. <view class="info-id" v-if="item.uid">
  33. UID:{{item.uid}}
  34. </view>
  35. </view>
  36. <view class="set">
  37. <image src="../../../static/images/sc.png" mode="" @click="scAccount(item,index)"></image>
  38. </view>
  39. </view>
  40. </template>
  41. <!-- 添加账号 -->
  42. <view class="account-wrap" @click="openAdd" v-if="menList.length < maxAccountNum">
  43. <image src="../../../static/images/add.png" mode="" class="add"></image>
  44. <view class="u-info">
  45. 添加帐号
  46. </view>
  47. <view class="set">
  48. </view>
  49. </view>
  50. <!-- 添加账号弹窗 -->
  51. <uni-popup type="center" ref="add">
  52. <view class="whiteBg" >
  53. <view class="tips">
  54. <view class="tips-btn on">
  55. <view>添加账号</view>
  56. <!-- <view class="line"></view> -->
  57. </view>
  58. </view>
  59. <view class="list">
  60. <!-- <form @submit.prevent="submit"> -->
  61. <view class="item">
  62. <view class="acea-row row-middle">
  63. <image src="../static/phone_1.png" class="itemImg-add"></image>
  64. <input type="text" placeholder="输入手机号码" v-model="account" maxlength="11" required />
  65. </view>
  66. </view>
  67. <view class="item">
  68. <view class="acea-row row-middle">
  69. <image src="../static/code_1.png" class="item-img"></image>
  70. <input type="password" placeholder="填写登录密码" v-model="password" required />
  71. </view>
  72. </view>
  73. <!-- </form> -->
  74. </view>
  75. <view class="logon" @click="addAccount">添加账号</view>
  76. </view>
  77. </uni-popup>
  78. <view class="tipaddress" v-show="isCancellation">
  79. <view class="top"></view>
  80. <view class="bottom">
  81. <view class="font1">是否确认删除</view>
  82. <view class="font2">当前记录将被删除,您确认要删除吗?</view>
  83. <view class="btn">
  84. <view class="cancellation-btn btn-sty flex-aj-center" @tap="cancelUser">删除</view>
  85. <view class="cancel btn-sty flex-aj-center" @tap="isCancellation = false">
  86. 取消
  87. </view>
  88. </view>
  89. </view>
  90. </view>
  91. </view>
  92. </template>
  93. <script>
  94. import colors from '@/mixins/color.js';
  95. import {
  96. loginH5,
  97. loginMobile,
  98. registerVerify,
  99. register,
  100. getCodeApi,
  101. getUserInfo,
  102. appleLogin
  103. } from "@/api/user";
  104. const BACK_URL = "login_back_url";
  105. export default {
  106. mixins: [colors],
  107. data() {
  108. return {
  109. isCancellation: false,
  110. menList: [],
  111. userInfo: {},
  112. account: '',
  113. password: '',
  114. maxAccountNum: 6,
  115. scitem: {},
  116. scindex: '',
  117. keyLock: true
  118. }
  119. },
  120. onLoad() {
  121. this.getUserInfo()
  122. this.getMenList()
  123. },
  124. onShow() {
  125. },
  126. onReachBottom() {
  127. },
  128. onReady() {
  129. },
  130. methods: {
  131. // 删除账号
  132. cancelUser() {
  133. let that = this;
  134. that.menList.splice(that.scindex,1);
  135. that.isCancellation = false;
  136. try{
  137. that.$io.storage("MenList.json", that.menList);
  138. }catch(e){
  139. console.log(e)
  140. //TODO handle the exception
  141. }
  142. },
  143. // 打开删除弹窗
  144. scAccount(item,index) {
  145. this.scitem = item;
  146. this.scindex = index;
  147. this.isCancellation = true;
  148. },
  149. // 添加账号
  150. addAccount() {
  151. let that = this;
  152. if (!that.account) {
  153. return that.$util.Tips({
  154. title: '请输入手机号码'
  155. });
  156. }
  157. if (!/^1(2|3|4|5|7|8|9|6)\d{9}$/i.test(that.account)) return that.$util.Tips({
  158. title: '请输入正确的手机号码'
  159. });
  160. if (!that.password) {
  161. return that.$util.Tips({
  162. title: '请填写登录密码'
  163. });
  164. }
  165. // for(let i = 0;i=)
  166. let i = false;
  167. this.menList.forEach(item => {
  168. if(item.account == that.account) {
  169. i = true
  170. }
  171. })
  172. if(!i) {
  173. try{
  174. that.menList.push({
  175. account: that.account,
  176. password: that.password
  177. })
  178. that.$io.storage("MenList.json", that.menList).then(e => {
  179. console.log('结果返回:',e)
  180. that.account = ''
  181. that.password = ''
  182. });
  183. }catch(e){
  184. }
  185. }else {
  186. return that.$util.Tips({
  187. title: '当前账号已存在'
  188. });
  189. }
  190. that.$refs.add.close()
  191. },
  192. // 打开添加弹窗
  193. openAdd() {
  194. this.$refs.add.open();
  195. },
  196. getUserInfo() {
  197. let that = this;
  198. getUserInfo().then(res => {
  199. that.userInfo = res.data;
  200. });
  201. },
  202. getMenList() {
  203. let that = this;
  204. try {
  205. that.$io.read("MenList.json").then(res => {
  206. // res 读取的文件内容
  207. that.menList = JSON.parse(res);
  208. }).catch(err => {
  209. // 找不到该文件就写入一个空白文件。
  210. // that.$io.storage("MenList.json", []);
  211. console.log(err, "err");
  212. })
  213. } catch (e) {
  214. console.log(e);
  215. }
  216. },
  217. login(item) {
  218. try{
  219. let that = this;
  220. if (that.keyLock) {
  221. that.keyLock = !that.keyLock
  222. } else {
  223. return that.$util.Tips({
  224. title: '请勿重复点击'
  225. });
  226. }
  227. loginH5({
  228. account: item.account,
  229. password: item.password,
  230. })
  231. .then(({
  232. data
  233. }) => {
  234. console.log('登录成功:',data)
  235. that.$store.commit("LOGIN", {
  236. 'token': data.token,
  237. 'time': data.expires_time - that.$Cache.time()
  238. });
  239. let backUrl = "/pages/user/index";
  240. that.$Cache.clear(BACK_URL);
  241. getUserInfo().then(res => {
  242. console.log('获取用户信息成功:',res)
  243. that.keyLock = true
  244. that.$store.commit("SETUID", res.data.uid);
  245. that.$store.commit("UPDATE_USERINFO", res.data);
  246. console.log('开始跳转:')
  247. uni.reLaunch({
  248. url: backUrl
  249. });
  250. console.log('跳转结束:')
  251. }).catch(error => {
  252. this.keyLock = true
  253. })
  254. })
  255. .catch(e => {
  256. this.keyLock = true
  257. that.$util.Tips({
  258. title: e
  259. });
  260. });
  261. }catch(e){
  262. //TODO handle the exception
  263. console.log('错误:',e)
  264. }
  265. }
  266. }
  267. }
  268. </script>
  269. <style lang="scss">
  270. .main-color {
  271. color: var(--view-theme);
  272. }
  273. .tit {
  274. font-size: 36rpx;
  275. text-align: center;
  276. font-weight: bold;
  277. padding: 100rpx 0;
  278. }
  279. .account-wrap {
  280. width: 690rpx;
  281. height: 150rpx;
  282. margin: auto;
  283. margin-bottom: 20rpx;
  284. background-color: #fff;
  285. display: flex;
  286. justify-content: flex-start;
  287. align-items: center;
  288. padding: 30rpx;
  289. border-radius: 20rpx;
  290. .u-logo {
  291. width: 90rpx;
  292. height: 90rpx;
  293. border-radius: 50%;
  294. flex-shrink: 0;
  295. }
  296. .add {
  297. width: 90rpx;
  298. height: 90rpx;
  299. flex-shrink: 0;
  300. }
  301. .u-info {
  302. flex-grow: 1;
  303. display: flex;
  304. flex-direction: column;
  305. justify-content: space-around;
  306. align-items: flex-start;
  307. padding-left: 25rpx;
  308. font-size: 28rpx;
  309. color: #999;
  310. .info-id {
  311. color: #999;
  312. }
  313. .info-name {
  314. font-weight: bold;
  315. font-size: 36rpx;
  316. color: #333333;
  317. }
  318. }
  319. .set {
  320. width: 140rpx;
  321. display: flex;
  322. align-items: center;
  323. justify-content: center;
  324. .new-use {
  325. font-size: 28rpx;
  326. font-weight: bold;
  327. text {
  328. display: inline-block;
  329. width: 20rpx;
  330. height: 20rpx;
  331. background-color: #08c05f;
  332. border-radius: 50%;
  333. margin-right: 10rpx;
  334. }
  335. }
  336. image {
  337. width: 32rpx;
  338. height: 32rpx;
  339. }
  340. }
  341. }
  342. .whiteBg {
  343. background-color: #fff;
  344. margin: -30rpx 56rpx 0rpx 56rpx;
  345. box-shadow: 0px 2px 14px 0px rgba(0, 0, 0, 0.08);
  346. border-radius: 8px;
  347. padding: 60rpx;
  348. .tips {
  349. display: flex;
  350. align-items: center;
  351. justify-content: center;
  352. height: 50rpx;
  353. margin: 40rpx;
  354. color: #999;
  355. .tips-btn {
  356. margin: 0 31rpx 0 48rpx;
  357. color: #999999;
  358. font-weight: bold;
  359. font-size: 32rpx;
  360. /* Safari 与 Chrome */
  361. .line {
  362. width: 80rpx;
  363. height: 6rpx;
  364. background: linear-gradient(135deg, var(--view-minorColor) 0%, var(--view-theme) 100%);
  365. border-radius: 2px;
  366. margin: 10rpx auto 0 auto;
  367. animation: myfirst .3s;
  368. -webkit-animation: myfirst .3s;
  369. }
  370. .none {
  371. width: 80rpx;
  372. background: #fff;
  373. height: 6rpx;
  374. }
  375. }
  376. @keyframes myfirst {
  377. 0% {
  378. width: 0rpx;
  379. }
  380. 100% {
  381. width: 80rpx;
  382. }
  383. }
  384. @-webkit-keyframes myfirst
  385. /* Safari 与 Chrome */
  386. {
  387. 0% {
  388. width: 0rpx;
  389. }
  390. 100% {
  391. width: 80rpx;
  392. }
  393. }
  394. .tips-btn.on {
  395. font-size: 36rpx;
  396. color: var(--view-theme);
  397. }
  398. }
  399. .list {
  400. border-radius: 16rpx;
  401. overflow: hidden;
  402. .forgetPwd {
  403. text-align: right;
  404. margin-top: 10rpx;
  405. color: #666666;
  406. font-size: 24rpx;
  407. }
  408. .item {
  409. border-bottom: 1px solid #F0F0F0;
  410. background: #fff;
  411. .row-middle {
  412. position: relative;
  413. padding: 16rpx 25rpx;
  414. input {
  415. flex: 1;
  416. font-size: 28rpx;
  417. height: 80rpx;
  418. }
  419. .spread {
  420. flex: 1;
  421. font-size: 28rpx;
  422. height: 80rpx;
  423. }
  424. .code {
  425. position: absolute;
  426. right: 30rpx;
  427. top: 50%;
  428. color: var(--view-theme);
  429. font-size: 26rpx;
  430. transform: translateY(-50%);
  431. }
  432. }
  433. }
  434. }
  435. .logon {
  436. display: flex;
  437. align-items: center;
  438. justify-content: center;
  439. width: 100%;
  440. height: 86rpx;
  441. margin-top: 48rpx;
  442. background: linear-gradient(135deg, var(--view-minorColor) 0%, var(--view-theme) 100%);
  443. border-radius: 120rpx;
  444. color: #FFFFFF;
  445. font-size: 30rpx;
  446. }
  447. }
  448. .code img {
  449. width: 100%;
  450. height: 100%;
  451. }
  452. .acea-row.row-middle {
  453. input {
  454. margin-left: 20rpx;
  455. display: block;
  456. }
  457. }
  458. .itemImg-add {
  459. width: 24rpx;
  460. height: 34rpx;
  461. }
  462. .item-img {
  463. width: 28rpx;
  464. height: 32rpx;
  465. }
  466. .tipaddress {
  467. position: fixed;
  468. left: 13%;
  469. top: 25%;
  470. // margin-left: -283rpx;
  471. width: 560rpx;
  472. height: 614rpx;
  473. background-color: #fff;
  474. border-radius: 10rpx;
  475. z-index: 100;
  476. text-align: center;
  477. .top {
  478. width: 560rpx;
  479. height: 270rpx;
  480. border-top-left-radius: 10rpx;
  481. border-top-right-radius: 10rpx;
  482. background-image: url('../../../static/images/address.png');
  483. background-repeat: round;
  484. background-color: #E93323;
  485. .tipsphoto {
  486. display: inline-block;
  487. width: 200rpx;
  488. height: 200rpx;
  489. margin-top: 73rpx;
  490. }
  491. }
  492. .bottom {
  493. font-size: 32rpx;
  494. font-weight: 400;
  495. .font1 {
  496. font-size: 36rpx;
  497. font-weight: 600;
  498. color: #333333;
  499. margin: 32rpx 0rpx 22rpx;
  500. }
  501. .font2 {
  502. color: #666666;
  503. margin-bottom: 48rpx;
  504. }
  505. .btn {
  506. display: flex;
  507. margin: 0 20rpx;
  508. .btn-sty {
  509. height: 82rpx;
  510. border-radius: 42rpx;
  511. line-height: 82rpx;
  512. padding: 24rpx 78rpx;
  513. margin: 0 auto;
  514. }
  515. .cancellation-btn {
  516. background-color: #F5F5F5;
  517. color: #333333;
  518. }
  519. .cancel {
  520. color: #FFFFFF;
  521. background: linear-gradient(90deg, #F67A38 0%, #F11B09 100%);
  522. }
  523. }
  524. }
  525. }
  526. </style>