WHeader.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. <template>
  2. <div class="w-header">
  3. <div v-if="tabActive" class="w-header-row">
  4. <div class="w-header-row-left">
  5. <ul>
  6. <li :class="tabActive==='todo'?'active':''">
  7. <a href="javascript:void(0)" @click="tabPage('todo')"><i class="ft icon">&#xe89e;</i>{{$L('待办')}}</a>
  8. </li><li :class="tabActive==='project'?'active':''">
  9. <a href="javascript:void(0)" @click="tabPage('project')"><i class="ft icon">&#xe6b8;</i>{{$L('项目')}}</a>
  10. </li><li :class="tabActive==='docs'?'active':''">
  11. <a href="javascript:void(0)" @click="tabPage('docs')"><i class="ft icon">&#xe915;</i>{{$L('知识库')}}</a>
  12. </li><li :class="tabActive==='team'?'active':''">
  13. <a href="javascript:void(0)" @click="tabPage('team')"><i class="ft icon">&#xe90d;</i>{{$L('团队')}}</a>
  14. </li>
  15. </ul>
  16. </div>
  17. <div class="w-header-row-right">
  18. <Dropdown class="right-info" trigger="click" @on-click="setRightSelect" placement="bottom-end" transfer>
  19. <div>
  20. <span class="username">{{$L('欢迎您')}}, {{(userInfo.nickname || userInfo.username) || $L('尊敬的会员')}}</span>
  21. <Icon type="md-arrow-dropdown"/>
  22. </div>
  23. <Dropdown-menu slot="list">
  24. <Dropdown-item v-if="isAdmin" name="system">{{$L('系统设置')}}</Dropdown-item>
  25. <Dropdown-item name="user">{{$L('个人中心')}}</Dropdown-item>
  26. <Dropdown-item name="out">{{$L('退出登录')}}</Dropdown-item>
  27. </Dropdown-menu>
  28. </Dropdown>
  29. <div class="right-info" @click="chatDrawerShow=true">
  30. <Icon class="right-mticon" type="md-notifications" size="24"/>
  31. <em v-if="chatUnreadTotal > 0" class="right-info-num">{{chatUnreadTotal > 99 ? '99+' : chatUnreadTotal}}</em>
  32. </div>
  33. <Dropdown class="right-info" trigger="click" @on-click="setLanguage" transfer>
  34. <div>
  35. <Icon class="right-mticon" type="md-globe" size="24"/>
  36. <Icon type="md-arrow-dropdown"/>
  37. </div>
  38. <Dropdown-menu slot="list">
  39. <Dropdown-item name="zh" :selected="getLanguage() === 'zh'">中文</Dropdown-item>
  40. <Dropdown-item name="en" :selected="getLanguage() === 'en'">English</Dropdown-item>
  41. </Dropdown-menu>
  42. </Dropdown>
  43. </div>
  44. </div>
  45. <WDrawer v-model="systemDrawerShow" maxWidth="640" :title="$L('系统设置')">
  46. <Form ref="formSystem" :model="formSystem" :label-width="100">
  47. <FormItem :label="$L('首页Logo')" prop="userimg">
  48. <ImgUpload v-model="formSystem.logo" :num="1"></ImgUpload>
  49. <span style="color:#777">{{$L('建议尺寸:%', '300x52')}}</span>
  50. </FormItem>
  51. <FormItem :label="$L('Github图标')" prop="userimg">
  52. <RadioGroup v-model="formSystem.github">
  53. <Radio label="show">{{$L('显示')}}</Radio>
  54. <Radio label="hidden">{{$L('隐藏')}}</Radio>
  55. </RadioGroup>
  56. </FormItem>
  57. <FormItem :label="$L('允许注册')" prop="userimg">
  58. <RadioGroup v-model="formSystem.reg">
  59. <Radio label="open">{{$L('允许')}}</Radio>
  60. <Radio label="close">{{$L('禁止')}}</Radio>
  61. </RadioGroup>
  62. </FormItem>
  63. <FormItem>
  64. <Button :loading="loadIng > 0" type="primary" @click="handleSubmit('formSystem')">{{$L('提交')}}</Button>
  65. <Button :loading="loadIng > 0" @click="handleReset('formSystem')" style="margin-left: 8px">{{$L('重置')}}</Button>
  66. </FormItem>
  67. </Form>
  68. </WDrawer>
  69. <WDrawer v-model="userDrawerShow" maxWidth="1000">
  70. <Tabs v-model="userDrawerTab">
  71. <TabPane :label="$L('个人资料')" name="personal">
  72. <Form ref="formDatum" :model="formDatum" :rules="ruleDatum" :label-width="80">
  73. <FormItem :label="$L('头像')" prop="userimg">
  74. <ImgUpload v-model="formDatum.userimg" :num="1"></ImgUpload>
  75. <span style="color:#777">{{$L('建议尺寸:%', '200x200')}}</span>
  76. </FormItem>
  77. <FormItem :label="$L('账号')">
  78. <Input v-model="userInfo.username" :disabled="true"></Input>
  79. </FormItem>
  80. <FormItem :label="$L('昵称')" prop="nickname">
  81. <Input v-model="formDatum.nickname"></Input>
  82. </FormItem>
  83. <FormItem :label="$L('职位/职称')" prop="profession">
  84. <Input v-model="formDatum.profession"></Input>
  85. </FormItem>
  86. <FormItem>
  87. <Button :loading="loadIng > 0" type="primary" @click="handleSubmit('formDatum')">{{$L('提交')}}</Button>
  88. <Button :loading="loadIng > 0" @click="handleReset('formDatum')" style="margin-left: 8px">{{$L('重置')}}</Button>
  89. </FormItem>
  90. </Form>
  91. </TabPane>
  92. <TabPane :label="$L('偏好设置')" name="setting">
  93. <Form ref="formSetting" :model="formSetting" :label-width="100">
  94. <FormItem :label="$L('系统皮肤')" prop="bgid">
  95. <ul class="setting-bg">
  96. <li v-for="i in [1,2,3,4,5,6,7,8,9,10,11,12]"
  97. :key="i"
  98. :style="`background-image:${getBgUrl(i, true)}`"
  99. :class="{active:formSetting.bgid==i}"
  100. @click="formSetting.bgid=i"></li>
  101. </ul>
  102. </FormItem>
  103. <FormItem>
  104. <Button :loading="loadIng > 0" type="primary" @click="handleSubmit('formSetting')">{{$L('提交')}}</Button>
  105. <Button :loading="loadIng > 0" @click="handleReset('formSetting')" style="margin-left: 8px">{{$L('重置')}}</Button>
  106. </FormItem>
  107. </Form>
  108. </TabPane>
  109. <TabPane :label="$L('账号密码')" name="account">
  110. <Form ref="formPass" :model="formPass" :rules="rulePass" :label-width="100">
  111. <FormItem :label="$L('旧密码')" prop="oldpass">
  112. <Input v-model="formPass.oldpass" type="password"></Input>
  113. </FormItem>
  114. <FormItem :label="$L('新密码')" prop="newpass">
  115. <Input v-model="formPass.newpass" type="password"></Input>
  116. </FormItem>
  117. <FormItem :label="$L('确认新密码')" prop="checkpass">
  118. <Input v-model="formPass.checkpass" type="password"></Input>
  119. </FormItem>
  120. <FormItem>
  121. <Button :loading="loadIng > 0" type="primary" @click="handleSubmit('formPass')">{{$L('提交')}}</Button>
  122. <Button :loading="loadIng > 0" @click="handleReset('formPass')" style="margin-left: 8px">{{$L('重置')}}</Button>
  123. </FormItem>
  124. </Form>
  125. </TabPane>
  126. <TabPane :label="$L('我创建的任务')" name="createtask">
  127. <header-create :canload="userDrawerShow && userDrawerTab == 'createtask'"></header-create>
  128. </TabPane>
  129. <TabPane :label="$L('我归档的任务')" name="archivedtask">
  130. <header-archived :canload="userDrawerShow && userDrawerTab == 'archivedtask'"></header-archived>
  131. </TabPane>
  132. </Tabs>
  133. </WDrawer>
  134. <WDrawer v-model="chatDrawerShow" :closable="false" maxWidth="1080">
  135. <chat-index v-model="chatUnreadTotal" :openWindow="chatDrawerShow" @on-open-notice="chatDrawerShow=true"></chat-index>
  136. <div class="w-header-chat-close" @click="chatDrawerShow=false"><Icon type="ios-close" /></div>
  137. </WDrawer>
  138. </div>
  139. </template>
  140. <style lang="scss">
  141. .w-header-chat-close {
  142. position: absolute;
  143. bottom: 0;
  144. left: 0;
  145. z-index: 1;
  146. color: #ffffff;
  147. font-size: 32px;
  148. width: 68px;
  149. height: 58px;
  150. line-height: 58px;
  151. text-align: center;
  152. cursor: pointer;
  153. > i {
  154. transition: all 0.2s;
  155. }
  156. &:hover {
  157. > i {
  158. transform: scale(1.12) rotate(90deg);
  159. }
  160. }
  161. }
  162. </style>
  163. <style lang="scss" scoped>
  164. .w-header {
  165. z-index: 15;
  166. position: fixed;
  167. left: 0;
  168. top: 0;
  169. right: 0;
  170. font-size: 14px;
  171. background: #0396f2 linear-gradient(45deg, #0396f2 0%, #0285d7 100%);
  172. box-shadow: 0 1px 5px 0 rgba(0, 0, 0, 0.25);
  173. .icon {
  174. font-size: 16px;
  175. margin-right: 3px;
  176. }
  177. .w-header-row {
  178. display: flex;
  179. color: #fff;
  180. height: 40px;
  181. position: relative;
  182. z-index: 10;
  183. margin: 0 32px;
  184. .w-header-row-left {
  185. flex: 1;
  186. white-space: nowrap;
  187. overflow: hidden;
  188. overflow-x: auto;
  189. -webkit-backface-visibility: hidden;
  190. -webkit-overflow-scrolling: touch;
  191. li {
  192. line-height: 40px;
  193. color: #fff;
  194. display: inline-block;
  195. a {
  196. color: #fff;
  197. display: block;
  198. min-width: 116px;
  199. text-align: center;
  200. &:visited {
  201. color: #fff;
  202. }
  203. &:hover {
  204. color: #f2f2f2;
  205. }
  206. }
  207. }
  208. li:hover, li.active {
  209. background: #0277c0;
  210. }
  211. }
  212. .w-header-row-right {
  213. white-space: nowrap;
  214. text-align: right;
  215. line-height: 40px;
  216. .right-info {
  217. display: inline-block;
  218. position: relative;
  219. margin-left: 12px;
  220. cursor: pointer;
  221. .right-mticon {
  222. vertical-align: top;
  223. margin-top: 8px;
  224. }
  225. .right-info-num {
  226. position: absolute;
  227. top: 2px;
  228. left: 12px;
  229. height: auto;
  230. line-height: normal;
  231. color: #ffffff;
  232. background-color: #ff0000;
  233. text-align: center;
  234. border-radius: 10px;
  235. padding: 1px 5px;
  236. font-size: 12px;
  237. transform: scale(0.9);
  238. z-index: 1;
  239. }
  240. }
  241. }
  242. }
  243. }
  244. .setting-bg {
  245. margin-top: 6px;
  246. margin-bottom: -24px;
  247. &:after,
  248. &:before {
  249. display: table;
  250. content: "";
  251. }
  252. li {
  253. margin: 0 16px 16px 0;
  254. width: 160px;
  255. height: 124px;
  256. display: inline-block;
  257. cursor: pointer;
  258. border: solid 2px #fff;
  259. background-repeat: no-repeat;
  260. background-position: center;
  261. background-size: cover;
  262. transition: all 0.2s;
  263. &.active,
  264. &:hover {
  265. border-color: #0396f2;
  266. transform: scale(1.02);
  267. }
  268. }
  269. }
  270. </style>
  271. <script>
  272. import ImgUpload from "./ImgUpload";
  273. import HeaderCreate from "./project/header/create";
  274. import HeaderArchived from "./project/header/archived";
  275. import ChatIndex from "./chat/Index";
  276. import WDrawer from "./iview/WDrawer";
  277. export default {
  278. name: 'WHeader',
  279. components: {WDrawer, ChatIndex, HeaderArchived, HeaderCreate, ImgUpload},
  280. data() {
  281. return {
  282. tabActive: '',
  283. loadIng: 0,
  284. userInfo: {},
  285. isAdmin: false,
  286. systemDrawerShow: false,
  287. userDrawerShow: false,
  288. userDrawerTab: 'personal',
  289. formSystem: {
  290. github: 'show',
  291. reg: 'open',
  292. },
  293. formDatum: {
  294. userimg: '',
  295. nickname: '',
  296. profession: ''
  297. },
  298. ruleDatum: { },
  299. formPass: {
  300. oldpass: '',
  301. newpass: '',
  302. checkpass: '',
  303. },
  304. rulePass: { },
  305. formSetting: {
  306. bgid: 0,
  307. },
  308. chatDrawerShow: false,
  309. chatUnreadTotal: 0,
  310. }
  311. },
  312. created() {
  313. this.ruleDatum = {
  314. nickname: [
  315. { required: true, message: this.$L('请输入昵称!'), trigger: 'change' },
  316. { type: 'string', min: 2, message: this.$L('昵称长度至少2位!'), trigger: 'change' }
  317. ]
  318. };
  319. this.rulePass = {
  320. oldpass: [
  321. { required: true, message: this.$L('请输入旧密码!'), trigger: 'change' },
  322. { type: 'string', min: 6, message: this.$L('密码长度至少6位!'), trigger: 'change' }
  323. ],
  324. newpass: [
  325. {
  326. validator: (rule, value, callback) => {
  327. if (value === '') {
  328. callback(new Error(this.$L('请输入新密码!')));
  329. } else {
  330. if (this.formPass.checkpass !== '') {
  331. this.$refs.formPass.validateField('checkpass');
  332. }
  333. callback();
  334. }
  335. },
  336. required: true,
  337. trigger: 'change'
  338. },
  339. { type: 'string', min: 6, message: this.$L('密码长度至少6位!'), trigger: 'change' }
  340. ],
  341. checkpass: [
  342. {
  343. validator: (rule, value, callback) => {
  344. if (value === '') {
  345. callback(new Error(this.$L('请输入确认新密码!')));
  346. } else if (value !== this.formPass.newpass) {
  347. callback(new Error(this.$L('两次密码输入不一致!')));
  348. } else {
  349. callback();
  350. }
  351. },
  352. required: true,
  353. trigger: 'change'
  354. }
  355. ],
  356. };
  357. },
  358. mounted() {
  359. let resCall = () => {
  360. this.$set(this.formDatum, 'userimg', this.userInfo.userimg)
  361. this.$set(this.formDatum, 'nickname', this.userInfo.nickname)
  362. this.$set(this.formDatum, 'profession', this.userInfo.profession)
  363. this.$set(this.formSetting, 'bgid', this.userInfo.bgid)
  364. };
  365. this.userInfo = $A.getUserInfo((res) => {
  366. this.userInfo = res;
  367. this.isAdmin = $A.identity('admin');
  368. resCall();
  369. }, false);
  370. this.isAdmin = $A.identity('admin');
  371. resCall();
  372. //
  373. this.tabActive = this.$route.meta.tabActive;
  374. //
  375. if ($A.hashParameter("open") === 'chat' && $A.getToken() !== false) {
  376. this.chatDrawerShow = true;
  377. }
  378. },
  379. watch: {
  380. '$route' () {
  381. this.tabActive = this.$route.meta.tabActive;
  382. this.systemDrawerShow = false;
  383. this.userDrawerShow = false;
  384. if ($A.hashParameter("open") === 'chat' && $A.getToken() !== false) {
  385. this.chatDrawerShow = true;
  386. }
  387. }
  388. },
  389. methods: {
  390. getBgUrl(id, thumb) {
  391. id = Math.max(1, parseInt(id));
  392. return 'url(' + window.location.origin + '/images/bg/' + (thumb ? 'thumb/' : '') + id + '.jpg' + ')';
  393. },
  394. tabPage(path) {
  395. this.goForward({path: '/' + path});
  396. },
  397. setRightSelect(act) {
  398. switch (act) {
  399. case 'system':
  400. this.systemSetting(false);
  401. this.systemDrawerShow = true;
  402. break;
  403. case 'user':
  404. this.userDrawerShow = true;
  405. break;
  406. case 'out':
  407. this.logout();
  408. break;
  409. }
  410. },
  411. logout() {
  412. this.$Modal.confirm({
  413. title: this.$L('退出登录'),
  414. content: this.$L('您确定要退出登录吗?'),
  415. onOk: () => {
  416. $A.userLogout();
  417. },
  418. });
  419. },
  420. systemSetting(save) {
  421. this.loadIng++;
  422. $A.aAjax({
  423. url: 'system/setting?type=' + (save ? 'save' : 'get'),
  424. data: this.formSystem,
  425. complete: () => {
  426. this.loadIng--;
  427. },
  428. success: (res) => {
  429. if (res.ret === 1) {
  430. this.formSystem = res.data;
  431. this.formSystem.github = this.formSystem.github || 'show';
  432. this.formSystem.reg = this.formSystem.reg || 'open';
  433. if (save) {
  434. this.$Message.success(this.$L('修改成功'));
  435. }
  436. } else {
  437. if (save) {
  438. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg });
  439. }
  440. }
  441. }
  442. });
  443. },
  444. handleSubmit(name) {
  445. this.$refs[name].validate((valid) => {
  446. if (valid) {
  447. switch (name) {
  448. case "formSystem": {
  449. this.systemSetting(true);
  450. break;
  451. }
  452. case "formDatum": {
  453. this.loadIng++;
  454. $A.aAjax({
  455. url: 'users/editdata',
  456. data: this.formDatum,
  457. complete: () => {
  458. this.loadIng--;
  459. },
  460. success: (res) => {
  461. if (res.ret === 1) {
  462. $A.getUserInfo(true);
  463. this.$Message.success(this.$L('修改成功'));
  464. } else {
  465. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg });
  466. }
  467. }
  468. });
  469. break;
  470. }
  471. case "formPass": {
  472. this.loadIng++;
  473. $A.aAjax({
  474. url: 'users/editpass',
  475. data: this.formPass,
  476. complete: () => {
  477. this.loadIng--;
  478. },
  479. success: (res) => {
  480. if (res.ret === 1) {
  481. this.userDrawerShow = false;
  482. this.$Message.success(this.$L('修改成功,请重新登录!'));
  483. this.$refs[name].resetFields();
  484. $A.userLogout();
  485. } else {
  486. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg });
  487. }
  488. }
  489. });
  490. break;
  491. }
  492. case "formSetting": {
  493. this.loadIng++;
  494. $A.aAjax({
  495. url: 'users/editdata',
  496. data: this.formSetting,
  497. complete: () => {
  498. this.loadIng--;
  499. },
  500. success: (res) => {
  501. if (res.ret === 1) {
  502. $A.getUserInfo(true);
  503. this.$Message.success(this.$L('修改成功'));
  504. } else {
  505. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg });
  506. }
  507. }
  508. });
  509. break;
  510. }
  511. }
  512. }
  513. })
  514. },
  515. handleReset(name) {
  516. this.$refs[name].resetFields();
  517. }
  518. },
  519. }
  520. </script>