WHeader.vue 26 KB

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