WHeader.vue 25 KB

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