WHeader.vue 22 KB

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