WHeader.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  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="userInfo.id==1" 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. systemDrawerShow: false,
  286. userDrawerShow: false,
  287. userDrawerTab: 'personal',
  288. formSystem: {
  289. github: 'show',
  290. reg: 'open',
  291. },
  292. formDatum: {
  293. userimg: '',
  294. nickname: '',
  295. profession: ''
  296. },
  297. ruleDatum: { },
  298. formPass: {
  299. oldpass: '',
  300. newpass: '',
  301. checkpass: '',
  302. },
  303. rulePass: { },
  304. formSetting: {
  305. bgid: 0,
  306. },
  307. chatDrawerShow: false,
  308. chatUnreadTotal: 0,
  309. }
  310. },
  311. created() {
  312. this.ruleDatum = {
  313. nickname: [
  314. { required: true, message: this.$L('请输入昵称!'), trigger: 'change' },
  315. { type: 'string', min: 2, message: this.$L('昵称长度至少2位!'), trigger: 'change' }
  316. ]
  317. };
  318. this.rulePass = {
  319. oldpass: [
  320. { required: true, message: this.$L('请输入旧密码!'), trigger: 'change' },
  321. { type: 'string', min: 6, message: this.$L('密码长度至少6位!'), trigger: 'change' }
  322. ],
  323. newpass: [
  324. {
  325. validator: (rule, value, callback) => {
  326. if (value === '') {
  327. callback(new Error(this.$L('请输入新密码!')));
  328. } else {
  329. if (this.formPass.checkpass !== '') {
  330. this.$refs.formPass.validateField('checkpass');
  331. }
  332. callback();
  333. }
  334. },
  335. required: true,
  336. trigger: 'change'
  337. },
  338. { type: 'string', min: 6, message: this.$L('密码长度至少6位!'), trigger: 'change' }
  339. ],
  340. checkpass: [
  341. {
  342. validator: (rule, value, callback) => {
  343. if (value === '') {
  344. callback(new Error(this.$L('请输入确认新密码!')));
  345. } else if (value !== this.formPass.newpass) {
  346. callback(new Error(this.$L('两次密码输入不一致!')));
  347. } else {
  348. callback();
  349. }
  350. },
  351. required: true,
  352. trigger: 'change'
  353. }
  354. ],
  355. };
  356. },
  357. mounted() {
  358. let resCall = () => {
  359. this.$set(this.formDatum, 'userimg', this.userInfo.userimg)
  360. this.$set(this.formDatum, 'nickname', this.userInfo.nickname)
  361. this.$set(this.formDatum, 'profession', this.userInfo.profession)
  362. this.$set(this.formSetting, 'bgid', this.userInfo.bgid)
  363. };
  364. this.userInfo = $A.getUserInfo((res) => {
  365. this.userInfo = res;
  366. resCall();
  367. }, false);
  368. resCall();
  369. //
  370. this.tabActive = this.$route.meta.tabActive;
  371. //
  372. if ($A.hashParameter("open") === 'chat' && $A.getToken() !== false) {
  373. this.chatDrawerShow = true;
  374. }
  375. },
  376. watch: {
  377. '$route' () {
  378. this.tabActive = this.$route.meta.tabActive;
  379. this.systemDrawerShow = false;
  380. this.userDrawerShow = false;
  381. if ($A.hashParameter("open") === 'chat' && $A.getToken() !== false) {
  382. this.chatDrawerShow = true;
  383. }
  384. }
  385. },
  386. methods: {
  387. getBgUrl(id, thumb) {
  388. id = Math.max(1, parseInt(id));
  389. return 'url(' + window.location.origin + '/images/bg/' + (thumb ? 'thumb/' : '') + id + '.jpg' + ')';
  390. },
  391. tabPage(path) {
  392. this.goForward({path: '/' + path});
  393. },
  394. setRightSelect(act) {
  395. switch (act) {
  396. case 'system':
  397. this.systemSetting(false);
  398. this.systemDrawerShow = true;
  399. break;
  400. case 'user':
  401. this.userDrawerShow = true;
  402. break;
  403. case 'out':
  404. this.logout();
  405. break;
  406. }
  407. },
  408. logout() {
  409. this.$Modal.confirm({
  410. title: this.$L('退出登录'),
  411. content: this.$L('您确定要退出登录吗?'),
  412. onOk: () => {
  413. $A.userLogout();
  414. },
  415. });
  416. },
  417. systemSetting(save) {
  418. this.loadIng++;
  419. $A.aAjax({
  420. url: 'system/setting?type=' + (save ? 'save' : 'get'),
  421. data: this.formSystem,
  422. complete: () => {
  423. this.loadIng--;
  424. },
  425. success: (res) => {
  426. if (res.ret === 1) {
  427. this.formSystem = res.data;
  428. this.formSystem.github = this.formSystem.github || 'show';
  429. this.formSystem.reg = this.formSystem.reg || 'open';
  430. if (save) {
  431. this.$Message.success(this.$L('修改成功'));
  432. }
  433. } else {
  434. if (save) {
  435. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg });
  436. }
  437. }
  438. }
  439. });
  440. },
  441. handleSubmit(name) {
  442. this.$refs[name].validate((valid) => {
  443. if (valid) {
  444. switch (name) {
  445. case "formSystem": {
  446. this.systemSetting(true);
  447. break;
  448. }
  449. case "formDatum": {
  450. this.loadIng++;
  451. $A.aAjax({
  452. url: 'users/editdata',
  453. data: this.formDatum,
  454. complete: () => {
  455. this.loadIng--;
  456. },
  457. success: (res) => {
  458. if (res.ret === 1) {
  459. $A.getUserInfo(true);
  460. this.$Message.success(this.$L('修改成功'));
  461. } else {
  462. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg });
  463. }
  464. }
  465. });
  466. break;
  467. }
  468. case "formPass": {
  469. this.loadIng++;
  470. $A.aAjax({
  471. url: 'users/editpass',
  472. data: this.formPass,
  473. complete: () => {
  474. this.loadIng--;
  475. },
  476. success: (res) => {
  477. if (res.ret === 1) {
  478. this.userDrawerShow = false;
  479. this.$Message.success(this.$L('修改成功,请重新登录!'));
  480. this.$refs[name].resetFields();
  481. $A.userLogout();
  482. } else {
  483. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg });
  484. }
  485. }
  486. });
  487. break;
  488. }
  489. case "formSetting": {
  490. this.loadIng++;
  491. $A.aAjax({
  492. url: 'users/editdata',
  493. data: this.formSetting,
  494. complete: () => {
  495. this.loadIng--;
  496. },
  497. success: (res) => {
  498. if (res.ret === 1) {
  499. $A.getUserInfo(true);
  500. this.$Message.success(this.$L('修改成功'));
  501. } else {
  502. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg });
  503. }
  504. }
  505. });
  506. break;
  507. }
  508. }
  509. }
  510. })
  511. },
  512. handleReset(name) {
  513. this.$refs[name].resetFields();
  514. }
  515. },
  516. }
  517. </script>