App.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <div id="app">
  3. <div class="bg"></div>
  4. <TopNav v-if="showNav" />
  5. <LeftNav v-if="showNav" />
  6. <div class="app_content">
  7. <router-view />
  8. </div>
  9. </div>
  10. </template>
  11. <script>
  12. import TopNav from "@/components/TopNav/TopNav";
  13. import LeftNav from "@/components/LeftNav/LeftNav";
  14. import { mapActions } from "vuex";
  15. export default {
  16. name: "App",
  17. provide() {
  18. return {
  19. checkCode: this.checkCode,
  20. };
  21. },
  22. components: {
  23. TopNav,
  24. LeftNav,
  25. },
  26. data() {
  27. return {
  28. showNav: false, // 是否显示导航
  29. };
  30. },
  31. computed: {},
  32. watch: {
  33. $route(to) {
  34. this.initUrl(to.query);
  35. if (
  36. to.name === "NotFound" ||
  37. to.name === "Login" ||
  38. to.name === "Forget" ||
  39. to.name === "Reg"
  40. ) {
  41. this.showNav = false;
  42. return;
  43. }
  44. this.showNav = true;
  45. },
  46. },
  47. created() {
  48. this.initUrl(this.$route.query);
  49. },
  50. mounted() {
  51. const { name } = this.$route;
  52. if (
  53. name === "NotFound" ||
  54. name === "Login" ||
  55. name === "Forget" ||
  56. name === "Reg"
  57. ) {
  58. this.showNav = false;
  59. }
  60. },
  61. methods: {
  62. ...mapActions([
  63. "userInfoAction",
  64. "queryAction",
  65. "isLoginAction",
  66. "userProfitAction",
  67. ]),
  68. // 获取已赚取佣金
  69. onProfit() {
  70. this.$api.profit().then((res) => {
  71. this.checkCode(res);
  72. const { code, data } = res.data;
  73. if (code) {
  74. return;
  75. }
  76. // 成功 todo
  77. this.userProfitAction(data);
  78. });
  79. },
  80. /**
  81. * 初始化路由地址
  82. */
  83. initUrl(query) {
  84. this.queryAction({ ...query });
  85. },
  86. // 校验返回值
  87. checkCode(res) {
  88. // 请求超时
  89. if (!res) {
  90. this.$notify({
  91. message: "当前网络拥堵, 请重试",
  92. type: "warning",
  93. });
  94. return;
  95. }
  96. const { code, msg } = res.data;
  97. if (!code) {
  98. return;
  99. }
  100. switch (code) {
  101. // 2 未登录
  102. case 2:
  103. localStorage.removeItem("userInfo");
  104. this.userInfoAction(false);
  105. this.userInfoAction({});
  106. this.$router.push({
  107. name: "Login",
  108. });
  109. this.$notify({
  110. message: msg,
  111. type: "warning",
  112. });
  113. break;
  114. default:
  115. this.$notify({
  116. message: msg,
  117. type: "warning",
  118. });
  119. }
  120. },
  121. // 请求用户信息
  122. getUserInfo() {
  123. this.$api.info().then((res) => {
  124. this.checkCode(res);
  125. const { data, code, msg } = res.data;
  126. // 错误
  127. if (code) {
  128. return;
  129. }
  130. // 成功
  131. this.$utils.setCookie("userInfo", JSON.stringify(data), 7);
  132. this.userInfoAction(data);
  133. // 用户佣金详情
  134. this.onProfit();
  135. });
  136. },
  137. },
  138. };
  139. </script>
  140. <style lang="less">
  141. .el-dialog {
  142. min-width: 500px !important;
  143. }
  144. #app {
  145. font-family: "Avenir", Helvetica, Arial, sans-serif;
  146. -webkit-font-smoothing: antialiased;
  147. -moz-osx-font-smoothing: grayscale;
  148. text-align: center;
  149. color: #555555;
  150. .bg {
  151. position: fixed;
  152. top: 0;
  153. left: 0;
  154. right: 0;
  155. bottom: 0;
  156. background-color: #f5f5f5;
  157. }
  158. .app_content {
  159. width: 90%;
  160. min-width: 1120px;
  161. margin: 0 auto;
  162. padding-top: 85px;
  163. padding-left: 200px;
  164. position: relative;
  165. z-index: 2;
  166. -webkit-box-sizing: border-box;
  167. box-sizing: border-box;
  168. }
  169. // 所有分页的样式
  170. .el-pager li,
  171. .el-pager li.btn-quickprev,
  172. .el-pager li.btn-quicknext,
  173. .el-pagination .btn-next,
  174. .el-pagination .btn-prev {
  175. font-size: 16px;
  176. font-weight: 500;
  177. background: transparent;
  178. &:hover {
  179. color: #409eff;
  180. }
  181. }
  182. .el-pager li.active {
  183. font-weight: 600;
  184. }
  185. .el-pagination button:disabled {
  186. color: #919fb9;
  187. &:hover {
  188. color: #919fb9;
  189. }
  190. }
  191. .el-pagination,
  192. .el-pager li.btn-quicknext,
  193. .el-pager li.btn-quickprev,
  194. .el-pagination .btn-next,
  195. .el-pagination .btn-prev {
  196. color: #555555;
  197. background-color: transparent;
  198. }
  199. .el-pagination__jump {
  200. color: #555555;
  201. }
  202. .el-textarea__inner {
  203. max-height: 100px;
  204. }
  205. textarea,
  206. textarea::-webkit-input-placeholder {
  207. font-family: "微软雅黑";
  208. }
  209. .el-input__inner {
  210. font-size: 16px;
  211. // color: #ededed;
  212. // border: 1px solid #686868;
  213. // background-color: transparent;
  214. // &:hover {
  215. // border: 1px solid #686868;
  216. // }
  217. }
  218. .el-textarea textarea {
  219. // overflow-y: hidden;
  220. }
  221. }
  222. .el-notification__content {
  223. margin: 0;
  224. }
  225. </style>