Login.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. <template>
  2. <div class="container">
  3. <div class="login-box">
  4. <div class="left">
  5. <div class="left-up-icon"></div>
  6. </div>
  7. <div class="right">
  8. <div class="title">
  9. <img
  10. class="title-logo"
  11. :src="cargoOwners[currentCompanyLevelTwo]?.logoUrl"
  12. alt=""
  13. />
  14. <div class="title-left">
  15. {{ cargoOwners[currentCompanyLevelTwo]?.cargoOwner }}
  16. </div>
  17. <div class="title-mid">丨</div>
  18. <div class="title-right">智慧航运管理平台</div>
  19. </div>
  20. <div class="form-container">
  21. <el-form :model="ruleForm" :rules="rules" ref="form">
  22. <el-form-item prop="phone">
  23. <el-input placeholder="请输入手机号" v-model="ruleForm.phone">
  24. <template v-slot:prepend>
  25. <el-button icon="el-icon-mobile-phone"></el-button>
  26. </template>
  27. </el-input>
  28. </el-form-item>
  29. <el-form-item prop="password">
  30. <el-input
  31. type="password"
  32. placeholder="请输入密码"
  33. v-model="ruleForm.password"
  34. >
  35. <template v-slot:prepend>
  36. <el-button icon="el-icon-lock"></el-button>
  37. </template>
  38. </el-input>
  39. </el-form-item>
  40. <el-form-item>
  41. <el-button
  42. style="
  43. width: 384px;
  44. height: 48px;
  45. border-radius: 2px;
  46. margin-top: 40px;
  47. "
  48. type="primary"
  49. @click="login('ruleForm')"
  50. >
  51. 登录
  52. </el-button>
  53. </el-form-item>
  54. </el-form>
  55. </div>
  56. <div class="df aic jcc" style="margin-top: 55px">
  57. <img
  58. style="height: 20px"
  59. src="https://6875-huihenduo-2gx127w7f837b584-1255802371.tcb.qcloud.la/miniapp-static/%E6%B1%87%E5%BE%88%E5%A4%9Alogo-%E5%B7%A6%E5%8F%B3.png"
  60. alt=""
  61. />
  62. <div
  63. style="
  64. height: 20px;
  65. line-height: 18px;
  66. font-size: 10px;
  67. color: #999;
  68. margin-left: 15px;
  69. "
  70. >
  71. 汇很多智慧航运研发中心
  72. </div>
  73. </div>
  74. </div>
  75. </div>
  76. <div @click="goBeian" class="copyright">
  77. Copyright © 2022 汇很多(江苏)科技有限公司 苏ICP备2022023253号-1 号
  78. </div>
  79. </div>
  80. </template>
  81. <script setup>
  82. import { ref, reactive, toRefs, computed, onMounted } from "vue";
  83. import { ElNotification } from "element-plus";
  84. import store from "../../store";
  85. import router from "../../router";
  86. import md5 from "md5";
  87. import api from "../../apis/fetch";
  88. const form = ref(null);
  89. let ruleForm = ref({
  90. phone: "",
  91. password: "",
  92. });
  93. const rules = ref({
  94. phone: [
  95. { required: true, message: "请输入手机号", trigger: "blur" },
  96. { min: 11, max: 11, message: "请正确输入手机号", trigger: "blur" },
  97. ],
  98. password: [
  99. { required: true, message: "请输入密码", trigger: "blur" },
  100. { min: 6, max: 20, message: "请正确输入手机号", trigger: "blur" },
  101. ],
  102. });
  103. function check() {
  104. // form.value.validate((valid) => {});
  105. }
  106. let cargoOwners = ref({
  107. // 嘉吉
  108. cargill: {
  109. cargoOwner: "嘉吉粮油",
  110. cargoOwnerId: 1,
  111. logoUrl:
  112. "https://6875-huihenduo-2gx127w7f837b584-1255802371.tcb.qcloud.la/web-static/jjly.jpg",
  113. },
  114. // 路易达孚
  115. lydf: {
  116. cargoOwner: "路易达孚",
  117. cargoOwnerId: 2,
  118. logoUrl:
  119. "https://6875-huihenduo-2gx127w7f837b584-1255802371.tcb.qcloud.la/lydf-web/lydf-logo.png",
  120. },
  121. // 泰兴邦基
  122. bunge: {
  123. cargoOwner: "泰兴邦基",
  124. cargoOwnerId: 3,
  125. logoUrl:
  126. "https://6875-huihenduo-2gx127w7f837b584-1255802371.tcb.qcloud.la/web-static/bunge.jpg",
  127. },
  128. // 双胞胎
  129. twins: {
  130. cargoOwnerId: 4,
  131. logoUrl: "",
  132. },
  133. // 东海粮油
  134. dhly: {
  135. cargoOwner: "东海粮油",
  136. cargoOwnerId: 5,
  137. logoUrl:
  138. "https://6875-huihenduo-2gx127w7f837b584-1255802371.tcb.qcloud.la/%E4%B8%9C%E6%B5%B7%E7%B2%AE%E6%B2%B9/dhly.png",
  139. },
  140. // 中储粮
  141. zcl: {
  142. cargoOwnerId: 6,
  143. logoUrl: "",
  144. },
  145. // 物产
  146. wuchan: {
  147. cargoOwner: "物产",
  148. cargoOwnerId: 7,
  149. logoUrl:
  150. "https://6875-huihenduo-2gx127w7f837b584-1255802371.tcb.qcloud.la/web-static/wuchan3.jpg",
  151. },
  152. // 浙江粮贸
  153. zjlm: {
  154. cargoOwnerId: 8,
  155. logoUrl: "",
  156. },
  157. // 货主公司
  158. cargo: {
  159. cargoOwnerId: 9,
  160. logoUrl: "",
  161. },
  162. // 浙江粮海
  163. zjlh: {
  164. cargoOwnerId: 10,
  165. logoUrl: "",
  166. },
  167. });
  168. function login() {
  169. form.value.validate(async (valid) => {
  170. if (valid) {
  171. let { phone, password } = ruleForm.value;
  172. let res = await api.staffLogin({
  173. phone,
  174. // password: md5(password).toUpperCase(),
  175. password,
  176. cargoOwnerId:
  177. cargoOwners.value[currentCompanyLevelTwo.value]?.cargoOwnerId ||
  178. cargoOwners.value["wuchan"]?.cargoOwnerId,
  179. });
  180. if (res.data.status == 0) {
  181. let {
  182. userId,
  183. userName,
  184. phone,
  185. contactName,
  186. loginAccountId,
  187. rolePermission,
  188. } = res.data.result;
  189. if (!rolePermission.length) {
  190. ElNotification.error({
  191. title: "失败",
  192. duration: 2000,
  193. message: "暂无权限,请联系管理员",
  194. type: "error",
  195. });
  196. return;
  197. }
  198. ElNotification.success({
  199. title: "成功",
  200. duration: 2000,
  201. message: res.data.msg,
  202. type: "success",
  203. });
  204. localStorage.setItem("userId", userId);
  205. localStorage.setItem("userName", userName);
  206. localStorage.setItem("phone", phone);
  207. localStorage.setItem("contactName", contactName);
  208. localStorage.setItem("userType", 1);
  209. localStorage.setItem("loginAccountId", loginAccountId);
  210. rolePermission = rolePermission || [];
  211. let arr = [...new Set([...rolePermission])];
  212. localStorage.setItem("rolePermission", arr);
  213. store.dispatch("GetBasePermissionData", localStorage.loginAccountId);
  214. let res1 = await store.dispatch(
  215. "GetUserPermission",
  216. localStorage.loginAccountId
  217. );
  218. router.replace("/");
  219. store.commit("changeLogin", true);
  220. } else {
  221. ElNotification.error({
  222. title: "错误",
  223. duration: 3000,
  224. message: res.data.msg,
  225. });
  226. }
  227. } else {
  228. console.log("error submit!!");
  229. return false;
  230. }
  231. });
  232. }
  233. function goBeian() {
  234. window.open("https://beian.miit.gov.cn/");
  235. }
  236. let currentCompanyLevelTwo = ref("");
  237. function getLevel2domain() {
  238. let baseurl = window.location.href;
  239. let index0 = baseurl.indexOf("localhost");
  240. if (index0 != -1) {
  241. currentCompanyLevelTwo.value = "wuchan";
  242. } else {
  243. let index1 = baseurl.indexOf("http://");
  244. let index2 = baseurl.indexOf(".");
  245. let plenth;
  246. if (index1 == -1) {
  247. plenth = 8;
  248. } else {
  249. plenth = 7;
  250. }
  251. currentCompanyLevelTwo.value = baseurl.substring(plenth, index2);
  252. }
  253. if (!cargoOwners.value[currentCompanyLevelTwo.value]?.cargoOwnerId) {
  254. currentCompanyLevelTwo.value = "wuchan";
  255. }
  256. console.log(currentCompanyLevelTwo.value);
  257. }
  258. onMounted(() => {
  259. getLevel2domain();
  260. });
  261. </script>
  262. <style scoped>
  263. .container {
  264. width: 100%;
  265. height: 100%;
  266. background-image: url(../../assets/login-back.png);
  267. background-size: cover;
  268. }
  269. .login-box {
  270. position: relative;
  271. display: flex;
  272. top: calc(50% - 255px);
  273. left: calc(50% - 478px);
  274. width: 966px;
  275. height: 508px;
  276. border-radius: 10px;
  277. overflow: hidden;
  278. }
  279. .left {
  280. height: 100%;
  281. width: 450px;
  282. background-image: url(../../assets/login-modal.png);
  283. }
  284. .left-up-icon {
  285. width: 40px;
  286. height: 40px;
  287. border-radius: 50%;
  288. margin: 24px;
  289. background-image: url(../../assets/logo.png);
  290. background-size: contain;
  291. }
  292. .right {
  293. height: 100%;
  294. width: 516px;
  295. background: #fff;
  296. }
  297. .title {
  298. padding-top: 100px;
  299. width: 384px;
  300. height: 38px;
  301. display: flex;
  302. margin: 0 auto;
  303. align-items: center;
  304. justify-content: space-between;
  305. color: #333;
  306. }
  307. .title-logo {
  308. max-width: 50px;
  309. max-height: 40px;
  310. object-fit: contain;
  311. }
  312. .title-left {
  313. font-size: 20px;
  314. }
  315. .title-mid {
  316. font-size: 24px;
  317. }
  318. .title-right {
  319. font-size: 20px;
  320. }
  321. .form-container {
  322. margin: 0 auto;
  323. margin-top: 60px;
  324. width: 384px;
  325. }
  326. .copyright {
  327. position: absolute;
  328. width: 100vw;
  329. bottom: 70px;
  330. text-align: center;
  331. font-family: PingFang SC;
  332. font-weight: 400;
  333. color: #aaa;
  334. opacity: 0.8;
  335. cursor: pointer;
  336. }
  337. </style>