Navbar.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. <template>
  2. <el-menu
  3. :default-active="activeIndex"
  4. class="el-menu-demo"
  5. mode="horizontal"
  6. background-color=""
  7. text-color="#000"
  8. active-text-color="#4392f7"
  9. @select="handleSelect"
  10. >
  11. <el-icon
  12. :size="20"
  13. v-show="!menuclose"
  14. class="fold"
  15. @click="SpreadMenu(true)"
  16. ><Fold
  17. /></el-icon>
  18. <el-icon
  19. :size="20"
  20. v-show="menuclose"
  21. class="fold"
  22. @click="SpreadMenu(false)"
  23. ><Expand
  24. /></el-icon>
  25. <div class="logo">
  26. <img src="@/assets/nanchang.png" style="width: 30px; height: 30px" />
  27. <span>校车预约管理系统</span>
  28. </div>
  29. <div class="login">
  30. <span class="dateTime">{{ dateTime }}</span>
  31. <img
  32. src="@/assets/news.png"
  33. @click="newsClick"
  34. style="width: 20px; height: 20px; padding: 0 20px 0 0; cursor: pointer"
  35. alt=""
  36. />
  37. <div class="flex flex-wrap items-center" style="cursor: pointer">
  38. <el-dropdown :hide-on-click="false" trigger="click">
  39. <el-avatar :size="30">
  40. <img
  41. src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png"
  42. />
  43. </el-avatar>
  44. <template #dropdown>
  45. <el-dropdown-menu>
  46. <el-dropdown-item @click="uppassword">
  47. <el-icon class="switchButton" :size="20" color="#000">
  48. <Lock />
  49. </el-icon>
  50. <span>修改密码</span>
  51. </el-dropdown-item>
  52. <el-dialog
  53. :append-to-body="true"
  54. custom-class="pw"
  55. v-model="uppasswordShow"
  56. title="修改密码"
  57. width="30%"
  58. :before-close="uppasswordClose"
  59. align-center
  60. >
  61. <el-form
  62. ref="ruleFormRef"
  63. :model="ruleForm"
  64. :rules="rules"
  65. label-width="100px"
  66. class="demo-ruleForm"
  67. :size="formSize"
  68. label-position="left"
  69. status-icon
  70. >
  71. <el-form-item label="原密码" prop="oldpass">
  72. <el-input
  73. v-model="ruleForm.oldpass"
  74. placeholder="请输入原密码"
  75. />
  76. </el-form-item>
  77. <el-form-item label="新密码" prop="nowpass">
  78. <el-input
  79. v-model="ruleForm.nowpass"
  80. placeholder="请输入新密码"
  81. />
  82. </el-form-item>
  83. <el-form-item
  84. label="确定新密码"
  85. prop="correctpass"
  86. style="
  87. padding-bottom: 40px;
  88. border-bottom: 1px solid rgba(230, 230, 230, 1);
  89. "
  90. >
  91. <el-input
  92. v-model="ruleForm.correctpass"
  93. placeholder="请再次输入新密码"
  94. />
  95. </el-form-item>
  96. <el-form-item class="options">
  97. <el-button
  98. class="queding"
  99. type="primary"
  100. @click="submitForm(ruleFormRef)"
  101. >
  102. 确定
  103. </el-button>
  104. <el-button class="congzhi" @click="resetForm(ruleFormRef)"
  105. >重置</el-button
  106. >
  107. </el-form-item>
  108. </el-form>
  109. <!-- <template #footer>
  110. <span class="dialog-footer">
  111. <el-button @click="dialogVisible = false">取消</el-button>
  112. <el-button type="primary" @click="dialogVisible = false">
  113. 确定
  114. </el-button>
  115. </span>
  116. </template> -->
  117. </el-dialog>
  118. <el-dropdown-item @click="loginOut">
  119. <el-icon class="switchButton" :size="20" color="#000">
  120. <SwitchButton />
  121. </el-icon>
  122. <span>退出登录</span>
  123. </el-dropdown-item>
  124. </el-dropdown-menu>
  125. </template>
  126. </el-dropdown>
  127. </div>
  128. <span class="name">admin</span>
  129. </div>
  130. </el-menu>
  131. </template>
  132. <script setup>
  133. import { ref, reactive, onBeforeMount, onMounted, watch } from "vue";
  134. import { ElMessage, ElMessageBox } from "element-plus";
  135. import { useStore } from "vuex";
  136. import { useRouter } from "vue-router";
  137. import { dayjs } from "element-plus";
  138. const store = useStore();
  139. const router = useRouter();
  140. const activeIndex = ref(); // 路由路径
  141. const loginOutDialogVisible = ref(false); // 退出按钮
  142. const menuclose = ref(false); // 左边状态栏展开按钮状态
  143. const uppasswordShow = ref(false); // 修改密码展示框
  144. const ruleForm = reactive({
  145. oldpass: "",
  146. nowpass: "",
  147. correctpass: "",
  148. });
  149. const ruleFormRef = ref();
  150. // 表单验证
  151. const rules = reactive({
  152. oldpass: [
  153. {
  154. required: true,
  155. message: "密码不能为空",
  156. trigger: "blur",
  157. },
  158. ],
  159. nowpass: [
  160. {
  161. required: true,
  162. message: "新密码不能为空",
  163. trigger: "blur",
  164. },
  165. ],
  166. correctpass: [
  167. {
  168. required: true,
  169. message: "确定新密码是否正确",
  170. trigger: "blur",
  171. },
  172. ],
  173. // desc: [{ required: true, message: "Please input activity form", trigger: "blur" }],
  174. });
  175. // 点击消息通知
  176. const newsClick = () => {
  177. store.commit("indexUp", 0);
  178. router.push({
  179. path: `/schoolBus/news`,
  180. });
  181. };
  182. const dateTime = ref(
  183. dayjs().format("YYYY-MM-DD") + ` 星期四 ` + dayjs().format("HH:mm:ss")
  184. ); // 时间
  185. // 选择菜单
  186. const handleSelect = (key, keyPath) => {
  187. store.commit("navbarUpdata", key);
  188. activeIndex.value = key;
  189. };
  190. // 展开按钮
  191. const SpreadMenu = (flag) => {
  192. store.commit("menuClose", flag);
  193. menuclose.value = flag;
  194. };
  195. // 修改密码
  196. const uppassword = () => {
  197. uppasswordShow.value = true;
  198. };
  199. const uppasswordClose = () => {
  200. uppasswordShow.value = false;
  201. // ruleForm.oldpass = "";
  202. // ruleForm.nowpass = "";
  203. // ruleForm.correctpass = "";
  204. ruleFormRef.value.resetFields();
  205. };
  206. // 提交修改密码表单
  207. const submitForm = async (formEl) => {
  208. if (!formEl) return;
  209. await formEl.validate((valid, fields) => {
  210. if (valid) {
  211. // console.log("submit!");
  212. } else {
  213. console.log("error submit!", fields);
  214. }
  215. });
  216. };
  217. // 重置表单
  218. const resetForm = (formEl) => {
  219. // console.log("重置表单");
  220. if (!formEl) return;
  221. formEl.resetFields();
  222. };
  223. const loginOut = () => {
  224. ElMessageBox.confirm("是否退出登录?", "提示", {
  225. confirmButtonText: "确认",
  226. cancelButtonText: "取消",
  227. type: "warning",
  228. })
  229. .then(() => {
  230. sessionStorage.removeItem("token");
  231. router.push({
  232. path: `/login`,
  233. });
  234. ElMessage({
  235. type: "success",
  236. message: "退出成功",
  237. });
  238. })
  239. .catch(() => {
  240. ElMessage({
  241. type: "info",
  242. message: "已取消登录",
  243. });
  244. });
  245. };
  246. onBeforeMount(() => {
  247. activeIndex.value = store.state.user.navbar;
  248. // handleSelect("vidicons");
  249. setInterval(() => {
  250. var week = ["日", "一", "二", "三", "四", "五", "六"];
  251. var datas = dayjs().day();
  252. dateTime.value =
  253. dayjs().format("YYYY-MM-DD") +
  254. ` 星期${week[datas]} ` +
  255. dayjs().format("HH:mm:ss");
  256. }, 1000);
  257. });
  258. </script>
  259. <style scoped lang="scss">
  260. .el-menu--horizontal {
  261. border-bottom: none;
  262. display: flex;
  263. align-items: center;
  264. height: 65px;
  265. // width: 100%;
  266. background-color: #fff;
  267. box-shadow: 5px 5px 10px 0px rgba(213, 228, 252, 1);
  268. .logo {
  269. left: 90px;
  270. display: flex;
  271. align-items: center;
  272. span {
  273. margin-left: 10px;
  274. font-size: 24px;
  275. font-weight: 600;
  276. }
  277. }
  278. .login {
  279. color: #000;
  280. display: flex;
  281. align-items: center;
  282. position: absolute;
  283. right: 10px;
  284. top: 17px;
  285. .dateTime {
  286. margin-right: 20px;
  287. }
  288. .name {
  289. height: 20px;
  290. line-height: 20px;
  291. text-decoration: underline;
  292. padding: 0 10px;
  293. margin: 0 10px;
  294. border-left: 2px solid #ccc;
  295. }
  296. .switchButton {
  297. cursor: pointer;
  298. }
  299. }
  300. .login:focus {
  301. outline: none;
  302. }
  303. .fold {
  304. width: 46px;
  305. height: 65px;
  306. }
  307. .fold:hover {
  308. cursor: pointer;
  309. background-color: rgba(67, 146, 249, 0.1);
  310. }
  311. }
  312. </style>
  313. <style lang="scss">
  314. .el-overlay {
  315. .el-overlay-dialog {
  316. .pw {
  317. border-radius: 11px;
  318. .el-dialog__header {
  319. border-radius: 11px 11px 0 0;
  320. background: rgba(237, 241, 245, 1);
  321. font-weight: 600;
  322. margin: 0;
  323. .el-dialog__headerbtn {
  324. outline: none;
  325. }
  326. }
  327. .el-dialog__body {
  328. padding: 30px 20px 10px 20px;
  329. .el-input {
  330. width: 200px;
  331. }
  332. .options {
  333. margin-left: 170px;
  334. }
  335. }
  336. }
  337. }
  338. }
  339. </style>