WHeader.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  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. </WDrawer>
  110. </div>
  111. </template>
  112. <style lang="scss" scoped>
  113. .w-header {
  114. z-index: 15;
  115. position: fixed;
  116. left: 0;
  117. top: 0;
  118. right: 0;
  119. font-size: 14px;
  120. background: #0396f2 linear-gradient(45deg, #0396f2 0%, #0285d7 100%);
  121. box-shadow: 0 1px 5px 0 rgba(0, 0, 0, 0.25);
  122. .icon {
  123. font-size: 16px;
  124. margin-right: 3px;
  125. }
  126. .w-header-row {
  127. display: flex;
  128. color: #fff;
  129. height: 40px;
  130. position: relative;
  131. z-index: 10;
  132. margin: 0 32px;
  133. .w-header-row-left {
  134. flex: 1;
  135. white-space: nowrap;
  136. overflow: hidden;
  137. overflow-x: auto;
  138. -webkit-backface-visibility: hidden;
  139. -webkit-overflow-scrolling: touch;
  140. li {
  141. line-height: 40px;
  142. color: #fff;
  143. display: inline-block;
  144. a {
  145. color: #fff;
  146. display: block;
  147. width: 116px;
  148. text-align: center;
  149. &:visited {
  150. color: #fff;
  151. }
  152. &:hover {
  153. color: #f2f2f2;
  154. }
  155. }
  156. }
  157. li:hover, li.active {
  158. background: #0277c0;
  159. }
  160. }
  161. .w-header-row-right {
  162. white-space: nowrap;
  163. text-align: right;
  164. line-height: 40px;
  165. .right-info {
  166. display: inline-block;
  167. position: relative;
  168. margin-left: 12px;
  169. cursor: pointer;
  170. .right-mticon {
  171. vertical-align: top;
  172. margin-top: 8px;
  173. }
  174. }
  175. }
  176. }
  177. }
  178. .setting-bg {
  179. margin-top: 6px;
  180. margin-bottom: -24px;
  181. &:after,
  182. &:before {
  183. display: table;
  184. content: "";
  185. }
  186. li {
  187. margin: 0 16px 16px 0;
  188. width: 160px;
  189. height: 124px;
  190. display: inline-block;
  191. cursor: pointer;
  192. border: solid 2px #fff;
  193. background-repeat: no-repeat;
  194. background-position: center;
  195. background-size: cover;
  196. transition: all 0.2s;
  197. &.active,
  198. &:hover {
  199. border-color: #0396f2;
  200. transform: scale(1.02);
  201. }
  202. }
  203. }
  204. </style>
  205. <script>
  206. import ImgUpload from "./ImgUpload";
  207. import HeaderCreate from "./project/header/create";
  208. import HeaderArchived from "./project/header/archived";
  209. import ChatIndex from "./chat/Index";
  210. import WDrawer from "./iview/WDrawer";
  211. export default {
  212. name: 'WHeader',
  213. components: {WDrawer, ChatIndex, HeaderArchived, HeaderCreate, ImgUpload},
  214. data() {
  215. return {
  216. tabActive: '',
  217. loadIng: 0,
  218. userInfo: {},
  219. userDrawerShow: false,
  220. userDrawerTab: 'personal',
  221. formDatum: {
  222. userimg: '',
  223. nickname: '',
  224. profession: ''
  225. },
  226. ruleDatum: { },
  227. formPass: {
  228. oldpass: '',
  229. newpass: '',
  230. checkpass: '',
  231. },
  232. rulePass: { },
  233. formSetting: {
  234. bgid: 0,
  235. },
  236. chatDrawerShow: false,
  237. }
  238. },
  239. created() {
  240. this.ruleDatum = {
  241. nickname: [
  242. { required: true, message: this.$L('请输入昵称!'), trigger: 'change' },
  243. { type: 'string', min: 2, message: this.$L('昵称长度至少2位!'), trigger: 'change' }
  244. ]
  245. };
  246. this.rulePass = {
  247. oldpass: [
  248. { required: true, message: this.$L('请输入旧密码!'), trigger: 'change' },
  249. { type: 'string', min: 6, message: this.$L('密码长度至少6位!'), trigger: 'change' }
  250. ],
  251. newpass: [
  252. {
  253. validator: (rule, value, callback) => {
  254. if (value === '') {
  255. callback(new Error(this.$L('请输入新密码!')));
  256. } else {
  257. if (this.formPass.checkpass !== '') {
  258. this.$refs.formPass.validateField('checkpass');
  259. }
  260. callback();
  261. }
  262. },
  263. required: true,
  264. trigger: 'change'
  265. },
  266. { type: 'string', min: 6, message: this.$L('密码长度至少6位!'), trigger: 'change' }
  267. ],
  268. checkpass: [
  269. {
  270. validator: (rule, value, callback) => {
  271. if (value === '') {
  272. callback(new Error(this.$L('请输入确认新密码!')));
  273. } else if (value !== this.formPass.newpass) {
  274. callback(new Error(this.$L('两次密码输入不一致!')));
  275. } else {
  276. callback();
  277. }
  278. },
  279. required: true,
  280. trigger: 'change'
  281. }
  282. ],
  283. };
  284. },
  285. mounted() {
  286. let resCall = () => {
  287. this.$set(this.formDatum, 'userimg', this.userInfo.userimg)
  288. this.$set(this.formDatum, 'nickname', this.userInfo.nickname)
  289. this.$set(this.formDatum, 'profession', this.userInfo.profession)
  290. this.$set(this.formSetting, 'bgid', this.userInfo.bgid)
  291. };
  292. this.userInfo = $A.getUserInfo((res) => {
  293. this.userInfo = res;
  294. resCall();
  295. }, false);
  296. resCall();
  297. //
  298. this.tabActive = this.$route.meta.tabActive;
  299. },
  300. watch: {
  301. '$route' () {
  302. this.tabActive = this.$route.meta.tabActive;
  303. this.userDrawerShow = false;
  304. }
  305. },
  306. methods: {
  307. getBgUrl(id, thumb) {
  308. id = Math.max(1, parseInt(id));
  309. return 'url(' + window.location.origin + '/images/bg/' + (thumb ? 'thumb/' : '') + id + '.jpg' + ')';
  310. },
  311. tabPage(path) {
  312. this.goForward({path: '/' + path});
  313. },
  314. setRightSelect(act) {
  315. switch (act) {
  316. case 'user':
  317. this.userDrawerShow = true;
  318. break;
  319. case 'out':
  320. this.logout();
  321. break;
  322. }
  323. },
  324. logout() {
  325. this.$Modal.confirm({
  326. title: this.$L('退出登录'),
  327. content: this.$L('您确定要退出登录吗?'),
  328. onOk: () => {
  329. $A.userLogout();
  330. },
  331. });
  332. },
  333. handleSubmit(name) {
  334. this.$refs[name].validate((valid) => {
  335. if (valid) {
  336. switch (name) {
  337. case "formDatum": {
  338. this.loadIng++;
  339. $A.aAjax({
  340. url: 'users/editdata',
  341. data: this.formDatum,
  342. complete: () => {
  343. this.loadIng--;
  344. },
  345. success: (res) => {
  346. if (res.ret === 1) {
  347. $A.getUserInfo(true);
  348. this.$Message.success(this.$L('修改成功'));
  349. } else {
  350. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg });
  351. }
  352. }
  353. });
  354. break;
  355. }
  356. case "formPass": {
  357. this.loadIng++;
  358. $A.aAjax({
  359. url: 'users/editpass',
  360. data: this.formPass,
  361. complete: () => {
  362. this.loadIng--;
  363. },
  364. success: (res) => {
  365. if (res.ret === 1) {
  366. this.userDrawerShow = false;
  367. this.$Message.success(this.$L('修改成功,请重新登录!'));
  368. this.$refs[name].resetFields();
  369. $A.userLogout();
  370. } else {
  371. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg });
  372. }
  373. }
  374. });
  375. break;
  376. }
  377. case "formSetting": {
  378. this.loadIng++;
  379. $A.aAjax({
  380. url: 'users/editdata',
  381. data: this.formSetting,
  382. complete: () => {
  383. this.loadIng--;
  384. },
  385. success: (res) => {
  386. if (res.ret === 1) {
  387. $A.getUserInfo(true);
  388. this.$Message.success(this.$L('修改成功'));
  389. } else {
  390. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg });
  391. }
  392. }
  393. });
  394. break;
  395. }
  396. }
  397. }
  398. })
  399. },
  400. handleReset(name) {
  401. this.$refs[name].resetFields();
  402. }
  403. },
  404. }
  405. </script>