WHeader.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  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}}</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. right: -20%;
  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. }
  239. }
  240. }
  241. }
  242. }
  243. .setting-bg {
  244. margin-top: 6px;
  245. margin-bottom: -24px;
  246. &:after,
  247. &:before {
  248. display: table;
  249. content: "";
  250. }
  251. li {
  252. margin: 0 16px 16px 0;
  253. width: 160px;
  254. height: 124px;
  255. display: inline-block;
  256. cursor: pointer;
  257. border: solid 2px #fff;
  258. background-repeat: no-repeat;
  259. background-position: center;
  260. background-size: cover;
  261. transition: all 0.2s;
  262. &.active,
  263. &:hover {
  264. border-color: #0396f2;
  265. transform: scale(1.02);
  266. }
  267. }
  268. }
  269. </style>
  270. <script>
  271. import ImgUpload from "./ImgUpload";
  272. import HeaderCreate from "./project/header/create";
  273. import HeaderArchived from "./project/header/archived";
  274. import ChatIndex from "./chat/Index";
  275. import WDrawer from "./iview/WDrawer";
  276. export default {
  277. name: 'WHeader',
  278. components: {WDrawer, ChatIndex, HeaderArchived, HeaderCreate, ImgUpload},
  279. data() {
  280. return {
  281. tabActive: '',
  282. loadIng: 0,
  283. userInfo: {},
  284. systemDrawerShow: false,
  285. userDrawerShow: false,
  286. userDrawerTab: 'personal',
  287. formSystem: {
  288. github: 'show',
  289. reg: 'open',
  290. },
  291. formDatum: {
  292. userimg: '',
  293. nickname: '',
  294. profession: ''
  295. },
  296. ruleDatum: { },
  297. formPass: {
  298. oldpass: '',
  299. newpass: '',
  300. checkpass: '',
  301. },
  302. rulePass: { },
  303. formSetting: {
  304. bgid: 0,
  305. },
  306. chatDrawerShow: false,
  307. chatUnreadTotal: 0,
  308. }
  309. },
  310. created() {
  311. this.ruleDatum = {
  312. nickname: [
  313. { required: true, message: this.$L('请输入昵称!'), trigger: 'change' },
  314. { type: 'string', min: 2, message: this.$L('昵称长度至少2位!'), trigger: 'change' }
  315. ]
  316. };
  317. this.rulePass = {
  318. oldpass: [
  319. { required: true, message: this.$L('请输入旧密码!'), trigger: 'change' },
  320. { type: 'string', min: 6, message: this.$L('密码长度至少6位!'), trigger: 'change' }
  321. ],
  322. newpass: [
  323. {
  324. validator: (rule, value, callback) => {
  325. if (value === '') {
  326. callback(new Error(this.$L('请输入新密码!')));
  327. } else {
  328. if (this.formPass.checkpass !== '') {
  329. this.$refs.formPass.validateField('checkpass');
  330. }
  331. callback();
  332. }
  333. },
  334. required: true,
  335. trigger: 'change'
  336. },
  337. { type: 'string', min: 6, message: this.$L('密码长度至少6位!'), trigger: 'change' }
  338. ],
  339. checkpass: [
  340. {
  341. validator: (rule, value, callback) => {
  342. if (value === '') {
  343. callback(new Error(this.$L('请输入确认新密码!')));
  344. } else if (value !== this.formPass.newpass) {
  345. callback(new Error(this.$L('两次密码输入不一致!')));
  346. } else {
  347. callback();
  348. }
  349. },
  350. required: true,
  351. trigger: 'change'
  352. }
  353. ],
  354. };
  355. },
  356. mounted() {
  357. let resCall = () => {
  358. this.$set(this.formDatum, 'userimg', this.userInfo.userimg)
  359. this.$set(this.formDatum, 'nickname', this.userInfo.nickname)
  360. this.$set(this.formDatum, 'profession', this.userInfo.profession)
  361. this.$set(this.formSetting, 'bgid', this.userInfo.bgid)
  362. };
  363. this.userInfo = $A.getUserInfo((res) => {
  364. this.userInfo = res;
  365. resCall();
  366. }, false);
  367. resCall();
  368. //
  369. this.tabActive = this.$route.meta.tabActive;
  370. },
  371. watch: {
  372. '$route' () {
  373. this.tabActive = this.$route.meta.tabActive;
  374. this.systemDrawerShow = false;
  375. this.userDrawerShow = false;
  376. }
  377. },
  378. methods: {
  379. getBgUrl(id, thumb) {
  380. id = Math.max(1, parseInt(id));
  381. return 'url(' + window.location.origin + '/images/bg/' + (thumb ? 'thumb/' : '') + id + '.jpg' + ')';
  382. },
  383. tabPage(path) {
  384. this.goForward({path: '/' + path});
  385. },
  386. setRightSelect(act) {
  387. switch (act) {
  388. case 'system':
  389. this.systemSetting(false);
  390. this.systemDrawerShow = true;
  391. break;
  392. case 'user':
  393. this.userDrawerShow = true;
  394. break;
  395. case 'out':
  396. this.logout();
  397. break;
  398. }
  399. },
  400. logout() {
  401. this.$Modal.confirm({
  402. title: this.$L('退出登录'),
  403. content: this.$L('您确定要退出登录吗?'),
  404. onOk: () => {
  405. $A.userLogout();
  406. },
  407. });
  408. },
  409. systemSetting(save) {
  410. this.loadIng++;
  411. $A.aAjax({
  412. url: 'system/setting?type=' + (save ? 'save' : 'get'),
  413. data: this.formSystem,
  414. complete: () => {
  415. this.loadIng--;
  416. },
  417. success: (res) => {
  418. if (res.ret === 1) {
  419. this.formSystem = res.data;
  420. this.formSystem.github = this.formSystem.github || 'show';
  421. this.formSystem.reg = this.formSystem.reg || 'open';
  422. if (save) {
  423. this.$Message.success(this.$L('修改成功'));
  424. }
  425. } else {
  426. if (save) {
  427. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg });
  428. }
  429. }
  430. }
  431. });
  432. },
  433. handleSubmit(name) {
  434. this.$refs[name].validate((valid) => {
  435. if (valid) {
  436. switch (name) {
  437. case "formSystem": {
  438. this.systemSetting(true);
  439. break;
  440. }
  441. case "formDatum": {
  442. this.loadIng++;
  443. $A.aAjax({
  444. url: 'users/editdata',
  445. data: this.formDatum,
  446. complete: () => {
  447. this.loadIng--;
  448. },
  449. success: (res) => {
  450. if (res.ret === 1) {
  451. $A.getUserInfo(true);
  452. this.$Message.success(this.$L('修改成功'));
  453. } else {
  454. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg });
  455. }
  456. }
  457. });
  458. break;
  459. }
  460. case "formPass": {
  461. this.loadIng++;
  462. $A.aAjax({
  463. url: 'users/editpass',
  464. data: this.formPass,
  465. complete: () => {
  466. this.loadIng--;
  467. },
  468. success: (res) => {
  469. if (res.ret === 1) {
  470. this.userDrawerShow = false;
  471. this.$Message.success(this.$L('修改成功,请重新登录!'));
  472. this.$refs[name].resetFields();
  473. $A.userLogout();
  474. } else {
  475. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg });
  476. }
  477. }
  478. });
  479. break;
  480. }
  481. case "formSetting": {
  482. this.loadIng++;
  483. $A.aAjax({
  484. url: 'users/editdata',
  485. data: this.formSetting,
  486. complete: () => {
  487. this.loadIng--;
  488. },
  489. success: (res) => {
  490. if (res.ret === 1) {
  491. $A.getUserInfo(true);
  492. this.$Message.success(this.$L('修改成功'));
  493. } else {
  494. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg });
  495. }
  496. }
  497. });
  498. break;
  499. }
  500. }
  501. }
  502. })
  503. },
  504. handleReset(name) {
  505. this.$refs[name].resetFields();
  506. }
  507. },
  508. }
  509. </script>