Navbar.vue 9.5 KB

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