switch.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. <template>
  2. <view>
  3. <view class="navbar">
  4. <view
  5. class="back"
  6. @tap="goBack">
  7. <uni-icons
  8. type="back"
  9. size="20"></uni-icons>
  10. </view>
  11. <view class="title">切换账号</view>
  12. </view>
  13. <!-- 页面内容 -->
  14. <view
  15. class="content"
  16. v-for="item in list"
  17. :key="item.uid">
  18. <view
  19. class="box"
  20. v-if="item.uid === uid">
  21. <!-- v-if="item.uid = " -->
  22. <p class="P1">昵称:{{ item.nickname }}</p>
  23. <p class="p2">ID: {{ item.uid }}</p>
  24. <p
  25. v-if="item.uid === userInfo.uid"
  26. style="
  27. color: #ff5500;
  28. margin-top: 20rpx;
  29. margin-left: 37rpx;
  30. "
  31. >当前登录</p>
  32. </view>
  33. <view
  34. class="boxi"
  35. v-else
  36. @click="choose(item.uid)">
  37. <p class="nc">昵称:{{ item.nickname }}</p>
  38. <p class="id">ID: {{ item.uid }}</p>
  39. <p
  40. v-if="item.uid === userInfo.uid"
  41. style="
  42. color: #fff2ef;
  43. margin-top: 20rpx;
  44. margin-left: 37rpx;
  45. "
  46. >当前登录</p
  47. >
  48. </view>
  49. </view>
  50. <button
  51. class="btn"
  52. @click="add"
  53. ><image
  54. src="../../static/icon/tj.png"
  55. style="width: 22rpx; height: 22rpx; margin-right: 20rpx"
  56. mode=""></image
  57. >添加新账号</button
  58. >
  59. <button
  60. class="btn1"
  61. @click="login"
  62. >登录选中账号</button
  63. >
  64. <button
  65. class="btn1"
  66. @click="logout"
  67. >退出登录</button
  68. >
  69. </view>
  70. </template>
  71. <script>
  72. import { mapState, mapMutations } from "vuex";
  73. import { myList, addZ, change_user, logout } from "@/api/user.js";
  74. export default {
  75. data() {
  76. return {
  77. list: [],
  78. uid: 0,
  79. };
  80. },
  81. onLoad() {
  82. this.myList();
  83. this.uid = this.userInfo.uid;
  84. // this.addZ()
  85. },
  86. methods: {
  87. // 获取账号列表
  88. async myList() {
  89. const res = await myList();
  90. console.log("111", res);
  91. this.list = res.data.list;
  92. },
  93. // 获取添加账号
  94. goBack() {
  95. uni.navigateTo({
  96. url: "/pages/userinfo/userinfo",
  97. });
  98. },
  99. choose(choose_uid) {
  100. this.uid = choose_uid;
  101. },
  102. add() {
  103. uni.showModal({
  104. title: "确认注册新账号",
  105. content: "您确定要注册新账号吗?",
  106. success: confirmRes => {
  107. if (confirmRes.confirm) {
  108. console.log("用户点击确定");
  109. addZ()
  110. .then(res => {
  111. console.log(111111, res);
  112. if (res.status === 200) {
  113. //弹出注册成功
  114. uni.showToast({
  115. title: "注册成功",
  116. duration: 2000,
  117. position: "top",
  118. });
  119. this.myList();
  120. } else {
  121. uni.showToast({
  122. title: res.msg,
  123. duration: 2000,
  124. position: "top",
  125. });
  126. }
  127. })
  128. .catch(res => {
  129. uni.showToast({
  130. title: "111",
  131. duration: 2000,
  132. position: "top",
  133. });
  134. });
  135. } else if (confirmRes.cancel) {
  136. console.log("用户点击取消");
  137. }
  138. },
  139. });
  140. },
  141. login() {
  142. uni.showModal({
  143. title: "确认切换账号",
  144. content: "您确定要切换账号吗?",
  145. success: confirmRes => {
  146. if (confirmRes.confirm) {
  147. console.log("用户点击确定");
  148. change_user({ uid: this.uid })
  149. .then(res => {
  150. // 弹出确认对话框
  151. uni.setStorageSync("token", res.data.token);
  152. uni.reLaunch({
  153. url: "/pages/index/index",
  154. });
  155. })
  156. .catch(res => {
  157. uni.showToast({
  158. title: "切换账号失败,网络异常",
  159. duration: 2000,
  160. position: "top",
  161. });
  162. });
  163. } else if (confirmRes.cancel) {
  164. console.log("用户点击取消");
  165. }
  166. },
  167. });
  168. },
  169. logout() {
  170. uni.showModal({
  171. title: "确认退出账号",
  172. content: "您确定要退出账号吗?",
  173. success: confirmRes => {
  174. if (confirmRes.confirm) {
  175. console.log("用户点击确定");
  176. change_user({ uid: this.uid })
  177. .then(res => {
  178. // 弹出确认对话框
  179. uni.setStorageSync("token", res.data.token);
  180. uni.reLaunch({
  181. // url: "/pages/index/index",
  182. url: "/pages/public/login",
  183. });
  184. })
  185. .catch(res => {
  186. uni.showToast({
  187. title: "切换账号失败,网络异常",
  188. duration: 2000,
  189. position: "top",
  190. });
  191. });
  192. } else if (confirmRes.cancel) {
  193. console.log("用户点击取消");
  194. }
  195. },
  196. });
  197. },
  198. },
  199. computed: {
  200. ...mapState("user", ["userInfo", "orderInfo", "hasLogin"]),
  201. },
  202. };
  203. </script>
  204. <style lang="scss">
  205. .navbar {
  206. height: 50rpx;
  207. background-color: #fff;
  208. display: flex;
  209. align-items: center;
  210. padding: 0 12rpx;
  211. }
  212. .back {
  213. width: 20rpx;
  214. height: 20rpx;
  215. display: flex;
  216. align-items: center;
  217. justify-content: center;
  218. }
  219. .back-icon {
  220. width: 12rpx;
  221. height: 12rpx;
  222. }
  223. .title {
  224. flex: 1;
  225. text-align: center;
  226. width: 142rpx;
  227. height: 34rpx;
  228. font-size: 36rpx;
  229. font-family: PingFang SC;
  230. font-weight: 500;
  231. color: #282828;
  232. line-height: 48rpx;
  233. }
  234. .box {
  235. margin-left: 24rpx;
  236. margin-top: 50rpx;
  237. width: 702rpx;
  238. height: 224rpx;
  239. background: #fffdf5;
  240. border: 2px solid #ff9205;
  241. box-shadow: 2rpx 1rpx 36rpx 0rpx rgba(218, 218, 218, 0.56);
  242. border-radius: 30rpx;
  243. }
  244. .box .P1 {
  245. display: flex;
  246. justify-content: flex-start;
  247. margin-top: 75rpx;
  248. margin-left: 37rpx;
  249. height: 28rpx;
  250. font-size: 30rpx;
  251. font-family: PingFang SC;
  252. font-weight: bold;
  253. color: #282828;
  254. line-height: 48rpx;
  255. }
  256. .box .p2 {
  257. width: 188rpx;
  258. height: 22rpx;
  259. margin-top: 25rpx;
  260. margin-left: 37rpx;
  261. font-size: 28rpx;
  262. font-family: PingFang SC;
  263. font-weight: 500;
  264. color: #666666;
  265. line-height: 48rpx;
  266. }
  267. .boxi {
  268. margin-left: 24rpx;
  269. margin-top: 50rpx;
  270. width: 702rpx;
  271. height: 224rpx;
  272. background: #fff;
  273. border: 2px;
  274. box-shadow: 2rpx 1rpx 36rpx 0rpx rgba(255, 255, 255, 0.56);
  275. border-radius: 30rpx;
  276. overflow: hidden;
  277. }
  278. .boxi .nc {
  279. margin-top: 48rpx;
  280. margin-left: 37rpx;
  281. height: 28rpx;
  282. font-size: 30rpx;
  283. font-family: PingFang SC;
  284. font-weight: bold;
  285. color: #282828;
  286. line-height: 48rpx;
  287. }
  288. .boxi .id {
  289. margin-top: 21rpx;
  290. margin-left: 37rpx;
  291. height: 22rpx;
  292. font-size: 28rpx;
  293. font-family: PingFang SC;
  294. font-weight: 500;
  295. color: #666666;
  296. line-height: 48rpx;
  297. }
  298. .btn {
  299. width: 702rpx;
  300. height: 82rpx;
  301. background: #ffffff;
  302. border-radius: 30rpx;
  303. margin-top: 18rpx;
  304. }
  305. .btn1 {
  306. margin-left: 65rpx;
  307. margin-top: 70rpx;
  308. width: 620rpx;
  309. height: 100rpx;
  310. background: #ff6b2e;
  311. border-radius: 50rpx;
  312. color: #fff;
  313. text-align: center;
  314. }
  315. </style>