WHeader.vue 23 KB

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