WHeader.vue 18 KB

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