Login.vue 9.4 KB

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