todo.vue 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. <template>
  2. <div class="w-main todo">
  3. <v-title>{{$L('待办')}}-{{$L('轻量级的团队在线协作')}}</v-title>
  4. <div class="w-nav">
  5. <div class="nav-row">
  6. <div class="w-nav-left">
  7. <div class="page-nav-left">
  8. <span><i class="ft icon">&#xE787;</i> {{$L('我的待办')}}</span>
  9. <div v-if="loadIng > 0" class="page-nav-loading"><w-loading></w-loading></div>
  10. <div v-else class="page-nav-refresh"><em @click="refreshTask">{{$L('刷新')}}</em></div>
  11. </div>
  12. </div>
  13. <div class="w-nav-flex"></div>
  14. <div class="w-nav-right">
  15. <span class="ft hover" @click="handleTodo('calendar')"><i class="ft icon">&#xE706;</i> {{$L('待办日程')}}</span>
  16. <span class="ft hover" @click="handleTodo('complete')"><i class="ft icon">&#xE73D;</i> {{$L('已完成的任务')}}</span>
  17. <span class="ft hover" @click="handleTodo('attention')"><i class="ft icon">&#xE748;</i> {{$L('我关注的任务')}}</span>
  18. <span class="ft hover" @click="handleTodo('report')"><i class="ft icon">&#xE743;</i> {{$L('周报/日报')}}</span>
  19. </div>
  20. </div>
  21. </div>
  22. <w-content>
  23. <div class="todo-main">
  24. <div v-for="subs in [['1', '2'], ['3', '4']]" class="todo-ul">
  25. <div v-for="index in subs" class="todo-li">
  26. <div class="todo-card">
  27. <div class="todo-card-head" :class="['p' + index]">
  28. <i class="ft icon flag">&#xE753;</i>
  29. <div class="todo-card-title">{{pTitle(index)}}</div>
  30. <label class="todo-input-box" :class="{active: !!taskDatas[index].focus}" @click="()=>{$set(taskDatas[index],'focus',true)}">
  31. <div class="todo-input-ibox" @click.stop="">
  32. <Input v-model="taskDatas[index].title" class="todo-input-enter" :placeholder="$L('在这里输入事项,回车即可保存')" @on-enter="addTask(index)"></Input>
  33. <div class="todo-input-close" @click="()=>{$set(taskDatas[index],'focus',false)}"><i class="ft icon">&#xE710;</i></div>
  34. </div>
  35. <div class="todo-input-pbox">
  36. <div class="todo-input-placeholder">{{$L('点击可快速添加需要处理的事项')}}</div>
  37. <div class="todo-input-close"><i class="ft icon">&#xE740;</i></div>
  38. </div>
  39. </label>
  40. </div>
  41. <div class="todo-card-content">
  42. <draggable
  43. v-model="taskDatas[index].lists"
  44. class="content-ul"
  45. group="task"
  46. draggable=".task-draggable"
  47. :animation="150"
  48. :disabled="taskSortDisabled"
  49. @sort="taskSortUpdate"
  50. @remove="taskSortUpdate">
  51. <div v-for="task in taskDatas[index].lists" class="content-li task-draggable" :key="task.id" :class="{complete:task.complete}" @click="openTaskModal(task)">
  52. <Icon v-if="task.complete" class="task-check" type="md-checkbox-outline" @click.stop="taskComplete(task, false)"/>
  53. <Icon v-else class="task-check" type="md-square-outline" @click.stop="taskComplete(task, true)"/>
  54. <div v-if="!!task.loadIng" class="task-loading"><w-loading></w-loading></div>
  55. <div v-if="task.overdue" class="task-overdue">[{{$L('超期')}}]</div>
  56. <div class="task-title">{{task.title}}</div>
  57. </div>
  58. <div v-if="taskDatas[index].hasMorePages === true" class="content-li more" @click="getTaskLists(index, true)">{{$L('加载更多')}}</div>
  59. </draggable>
  60. <div v-if="taskDatas[index].lists.length === 0 && taskDatas[index].loadIng == 0" class="content-empty">{{$L('恭喜你!已完成了所有待办')}}</div>
  61. <div v-if="taskDatas[index].loadIng > 0" class="content-loading"><w-loading></w-loading></div>
  62. </div>
  63. </div>
  64. </div>
  65. </div>
  66. </div>
  67. </w-content>
  68. <WDrawer v-model="todoDrawerShow" maxWidth="1000">
  69. <Tabs v-if="todoDrawerShow" v-model="todoDrawerTab">
  70. <TabPane :label="$L('待办日程')" name="calendar">
  71. <todo-calendar :canload="todoDrawerShow && todoDrawerTab == 'calendar'"></todo-calendar>
  72. </TabPane>
  73. <TabPane :label="$L('已完成的任务')" name="complete">
  74. <todo-complete :canload="todoDrawerShow && todoDrawerTab == 'complete'"></todo-complete>
  75. </TabPane>
  76. <TabPane :label="$L('我关注的任务')" name="attention">
  77. <todo-attention :canload="todoDrawerShow && todoDrawerTab == 'attention'"></todo-attention>
  78. </TabPane>
  79. </Tabs>
  80. </WDrawer>
  81. <WDrawer v-model="todoReportDrawerShow" maxWidth="1000">
  82. <Tabs v-if="todoReportDrawerShow" v-model="todoReportDrawerTab">
  83. <TabPane :label="$L('我的汇报')" name="my">
  84. <report-my :canload="todoReportDrawerShow && todoReportDrawerTab == 'my'"></report-my>
  85. </TabPane>
  86. <TabPane :label="$L('收到的汇报')" name="receive">
  87. <report-receive :canload="todoReportDrawerShow && todoReportDrawerTab == 'receive'"></report-receive>
  88. </TabPane>
  89. </Tabs>
  90. </WDrawer>
  91. </div>
  92. </template>
  93. <style lang="scss">
  94. .todo-input-enter {
  95. .ivu-input {
  96. border: 0;
  97. background-color: rgba(255, 255, 255, 0.9);
  98. }
  99. }
  100. </style>
  101. <style lang="scss" scoped>
  102. .todo {
  103. .todo-main {
  104. display: flex;
  105. flex-direction: column;
  106. align-items: center;
  107. justify-content: center;
  108. width: 100%;
  109. height: 100%;
  110. min-height: 500px;
  111. padding: 5px;
  112. .todo-ul {
  113. flex: 1;
  114. display: flex;
  115. flex-direction: row;
  116. align-items: center;
  117. justify-content: center;
  118. width: 100%;
  119. .todo-li {
  120. flex: 1;
  121. height: 100%;
  122. position: relative;
  123. .todo-card {
  124. position: absolute;
  125. top: 10px;
  126. left: 10px;
  127. right: 10px;
  128. bottom: 10px;
  129. display: flex;
  130. flex-direction: column;
  131. .todo-card-head {
  132. display: flex;
  133. align-items: center;
  134. padding: 0 10px;
  135. height: 38px;
  136. border-radius: 4px 4px 0 0;
  137. color: #ffffff;
  138. .ft.icon {
  139. transform: scale(1);
  140. }
  141. .flag {
  142. font-weight: bold;
  143. font-size: 14px;
  144. margin-right: 5px;
  145. min-width: 16px;
  146. }
  147. .todo-card-title {
  148. font-weight: bold;
  149. }
  150. .todo-input-box {
  151. flex: 1;
  152. display: flex;
  153. flex-direction: row;
  154. align-items: center;
  155. justify-content: flex-end;
  156. height: 100%;
  157. cursor: pointer;
  158. &:hover {
  159. .todo-input-placeholder {
  160. opacity: 1;
  161. }
  162. }
  163. &.active {
  164. .todo-input-pbox {
  165. display: none;
  166. }
  167. .todo-input-ibox {
  168. display: flex;
  169. }
  170. }
  171. .todo-input-placeholder {
  172. color: rgba(255, 255, 255, 0.6);
  173. padding-right: 6px;
  174. transition: all 0.2s;
  175. opacity: 0;
  176. }
  177. .todo-input-pbox,
  178. .todo-input-ibox {
  179. flex: 1;
  180. display: flex;
  181. flex-direction: row;
  182. align-items: center;
  183. justify-content: flex-end;
  184. padding-left: 14px;
  185. height: 100%;
  186. }
  187. .todo-input-ibox {
  188. display: none;
  189. }
  190. .todo-input-close {
  191. height: 100%;
  192. display: flex;
  193. align-items: center;
  194. padding-left: 8px;
  195. i {
  196. font-size: 18px;
  197. font-weight: normal;
  198. }
  199. }
  200. }
  201. &.p1 {
  202. background: rgba(248, 14, 21, 0.6);
  203. }
  204. &.p2 {
  205. background: rgba(236, 196, 2, 0.5);
  206. }
  207. &.p3 {
  208. background: rgba(0, 159, 227, 0.7);
  209. }
  210. &.p4 {
  211. background: rgba(121, 170, 28, 0.7);
  212. }
  213. }
  214. .todo-card-content {
  215. flex: 1;
  216. background-color: #f5f6f7;
  217. border-radius: 0 0 4px 4px;
  218. overflow: auto;
  219. transform: translateZ(0);
  220. .content-ul {
  221. display: flex;
  222. flex-direction: column;
  223. min-height: 20px;
  224. .content-li {
  225. display: flex;
  226. flex-direction: row;
  227. align-items: flex-start;
  228. width: 100%;
  229. padding: 8px;
  230. color: #444444;
  231. border-bottom: dotted 1px rgba(153, 153, 153, 0.25);
  232. position: relative;
  233. cursor: pointer;
  234. &.complete {
  235. color: #999999;
  236. .task-title {
  237. text-decoration: line-through;
  238. }
  239. }
  240. &.more {
  241. color: #666;
  242. justify-content: center;
  243. }
  244. .task-check {
  245. font-size: 16px;
  246. padding-right: 6px;
  247. padding-top: 3px;
  248. }
  249. .task-loading {
  250. width: 15px;
  251. height: 15px;
  252. margin-right: 6px;
  253. margin-top: 3px;
  254. }
  255. .task-overdue {
  256. color: #ff0000;
  257. padding-right: 2px;
  258. }
  259. .task-title {
  260. flex: 1;
  261. word-break: break-all;
  262. &:hover {
  263. color: #000000;
  264. }
  265. }
  266. }
  267. }
  268. .content-loading {
  269. width: 100%;
  270. height: 22px;
  271. text-align: center;
  272. margin-top: 8px;
  273. margin-bottom: 8px;
  274. }
  275. .content-empty {
  276. margin: 6px auto;
  277. text-align: center;
  278. color: #666;
  279. }
  280. }
  281. }
  282. }
  283. }
  284. }
  285. @media (max-width: 780px) {
  286. .todo-main {
  287. height: auto;
  288. .todo-ul {
  289. flex-direction: column;
  290. .todo-li {
  291. width: 100%;
  292. .todo-card {
  293. position: static;
  294. top: 0;
  295. right: 0;
  296. left: 0;
  297. bottom: 0;
  298. margin: 10px;
  299. display: flex;
  300. flex-direction: column;
  301. min-height: 320px;
  302. max-height: 520px;
  303. }
  304. }
  305. }
  306. }
  307. }
  308. }
  309. </style>
  310. <script>
  311. import draggable from 'vuedraggable'
  312. import WContent from "../components/WContent";
  313. import TodoCalendar from "../components/project/todo/calendar";
  314. import TodoComplete from "../components/project/todo/complete";
  315. import TodoAttention from "../components/project/todo/attention";
  316. import Task from "../mixins/task";
  317. import ReportMy from "../components/report/my";
  318. import ReportReceive from "../components/report/receive";
  319. import WDrawer from "../components/iview/WDrawer";
  320. export default {
  321. components: {
  322. WDrawer,
  323. ReportReceive,
  324. ReportMy, draggable, TodoAttention, TodoComplete, TodoCalendar, WContent},
  325. mixins: [
  326. Task
  327. ],
  328. data () {
  329. return {
  330. loadIng: 0,
  331. userInfo: {},
  332. taskDatas: {
  333. "1": {lists: [], hasMorePages: false},
  334. "2": {lists: [], hasMorePages: false},
  335. "3": {lists: [], hasMorePages: false},
  336. "4": {lists: [], hasMorePages: false},
  337. },
  338. taskSortData: '',
  339. taskSortDisabled: false,
  340. todoDrawerShow: false,
  341. todoDrawerTab: 'calendar',
  342. todoReportDrawerShow: false,
  343. todoReportDrawerTab: 'my',
  344. }
  345. },
  346. mounted() {
  347. if ($A.getToken() === false) {
  348. this.goForward({path: '/'}, true);
  349. return;
  350. }
  351. this.refreshTask();
  352. this.userInfo = $A.getUserInfo((res, isLogin) => {
  353. if (this.userInfo.id != res.id) {
  354. this.userInfo = res;
  355. isLogin && this.refreshTask();
  356. }
  357. }, false);
  358. //
  359. $A.setOnTaskInfoListener('pages/todo',(act, detail) => {
  360. if (detail.username != $A.getUserName()) {
  361. for (let level in this.taskDatas) {
  362. this.taskDatas[level].lists.some((task, i) => {
  363. if (task.id == detail.id) {
  364. this.taskDatas[level].lists.splice(i, 1);
  365. this.taskSortData = this.getTaskSort();
  366. return true;
  367. }
  368. });
  369. }
  370. return;
  371. }
  372. //特殊事件(非操作任务的)
  373. switch (act) {
  374. case 'deleteproject': // 删除项目
  375. case 'deletelabel': // 删除分类
  376. this.refreshTask();
  377. return;
  378. case 'addlabel': // 添加分类
  379. case "labelsort": // 调整分类排序
  380. case "tasksort": // 调整任务排序
  381. return;
  382. }
  383. //
  384. for (let level in this.taskDatas) {
  385. this.taskDatas[level].lists.some((task, i) => {
  386. if (task.id == detail.id) {
  387. this.taskDatas[level].lists.splice(i, 1, detail);
  388. return true;
  389. }
  390. });
  391. }
  392. //
  393. let addOrDelete = (isAdd) => {
  394. if (isAdd) {
  395. for (let level in this.taskDatas) {
  396. if (level == detail.level) {
  397. let index = this.taskDatas[level].lists.length;
  398. this.taskDatas[level].lists.some((task, i) => {
  399. if (detail.userorder > task.userorder || (detail.userorder == task.userorder && detail.id > task.id)) {
  400. index = i;
  401. return true;
  402. }
  403. });
  404. this.taskDatas[level].lists.splice(index, 0, detail);
  405. }
  406. }
  407. } else {
  408. for (let level in this.taskDatas) {
  409. this.taskDatas[level].lists.some((task, i) => {
  410. if (task.id == detail.id) {
  411. this.taskDatas[level].lists.splice(i, 1);
  412. return true;
  413. }
  414. });
  415. }
  416. }
  417. this.taskSortData = this.getTaskSort();
  418. };
  419. //
  420. switch (act) {
  421. case "title": // 标题
  422. case "desc": // 描述
  423. case "plannedtime": // 设置计划时间
  424. case "unplannedtime": // 取消计划时间
  425. case "complete": // 标记完成
  426. case "unfinished": // 标记未完成
  427. case "comment": // 评论
  428. // 这些都不用处理
  429. break;
  430. case "level": // 优先级
  431. for (let level in this.taskDatas) {
  432. this.taskDatas[level].lists.some((task, i) => {
  433. if (task.id == detail.id) {
  434. this.taskDatas[level].lists.splice(i, 1);
  435. return true;
  436. }
  437. });
  438. if (level == detail.level) {
  439. let index = this.taskDatas[level].lists.length;
  440. this.taskDatas[level].lists.some((task, i) => {
  441. if (detail.userorder > task.userorder || (detail.userorder == task.userorder && detail.id > task.id)) {
  442. index = i;
  443. return true;
  444. }
  445. });
  446. this.taskDatas[level].lists.splice(index, 0, detail);
  447. }
  448. }
  449. this.taskSortData = this.getTaskSort();
  450. break;
  451. case "create": // 创建任务
  452. case "username": // 负责人
  453. addOrDelete(detail.username == $A.getUserName());
  454. break;
  455. case "delete": // 删除任务
  456. case "archived": // 归档
  457. addOrDelete(false);
  458. break;
  459. case "unarchived": // 取消归档
  460. addOrDelete(true);
  461. break;
  462. }
  463. }, true);
  464. },
  465. deactivated() {
  466. this.todoDrawerShow = false;
  467. this.todoReportDrawerShow = false;
  468. },
  469. computed: {
  470. },
  471. watch: {
  472. },
  473. methods: {
  474. pTitle(p) {
  475. switch (p) {
  476. case "1":
  477. return this.$L("重要且紧急");
  478. case "2":
  479. return this.$L("重要不紧急");
  480. case "3":
  481. return this.$L("紧急不重要");
  482. case "4":
  483. return this.$L("不重要不紧急");
  484. }
  485. },
  486. refreshTask() {
  487. this.taskDatas = {
  488. "1": {lists: [], hasMorePages: false},
  489. "2": {lists: [], hasMorePages: false},
  490. "3": {lists: [], hasMorePages: false},
  491. "4": {lists: [], hasMorePages: false},
  492. };
  493. for (let i = 1; i <= 4; i++) {
  494. this.getTaskLists(i.toString());
  495. }
  496. },
  497. getTaskLists(index, isNext, withNextNum = 0) {
  498. let taskData = this.taskDatas[index];
  499. let currentPage = 1;
  500. let pagesize = 20;
  501. let withNextPage = false;
  502. //
  503. if (isNext === true) {
  504. if (taskData.hasMorePages !== true) {
  505. return;
  506. }
  507. currentPage = Math.max(1, $A.runNum(taskData['currentPage']));
  508. let tempLists = this.taskDatas[index].lists;
  509. if (tempLists.length >= currentPage * pagesize) {
  510. currentPage++;
  511. } else {
  512. withNextPage = true;
  513. }
  514. withNextNum = $A.runNum(withNextNum);
  515. }
  516. this.$set(taskData, 'hasMorePages', false);
  517. this.$set(taskData, 'loadIng', $A.runNum(taskData.loadIng) + 1);
  518. this.taskSortDisabled = true;
  519. this.loadIng++;
  520. $A.apiAjax({
  521. url: 'project/task/lists',
  522. data: {
  523. level: index,
  524. sorts: {key:'userorder', order:'desc'},
  525. page: currentPage,
  526. pagesize: pagesize,
  527. },
  528. complete: () => {
  529. this.loadIng--;
  530. this.taskSortDisabled = false;
  531. this.$set(taskData, 'loadIng', $A.runNum(taskData.loadIng) - 1);
  532. },
  533. success: (res) => {
  534. if (res.ret === 1) {
  535. let inLists;
  536. res.data.lists.forEach((data) => {
  537. inLists = false;
  538. taskData.lists.some((item, i) => {
  539. if (item.id == data.id) {
  540. taskData.lists.splice(i, 1, data);
  541. return inLists = true;
  542. }
  543. });
  544. if (!inLists) {
  545. taskData.lists.push(data);
  546. }
  547. });
  548. this.taskSortData = this.getTaskSort();
  549. this.$set(taskData, 'currentPage', res.data.currentPage);
  550. this.$set(taskData, 'hasMorePages', res.data.hasMorePages);
  551. if (res.data.currentPage && withNextPage && withNextNum < 5) {
  552. this.getTaskLists(index, true, withNextNum + 1);
  553. }
  554. } else {
  555. this.$set(taskData, 'lists', []);
  556. this.$set(taskData, 'hasMorePages', false);
  557. }
  558. }
  559. });
  560. },
  561. addTask(index) {
  562. let taskData = this.taskDatas[index];
  563. let title = $A.trim(taskData.title);
  564. if ($A.count(title) == 0) {
  565. return;
  566. }
  567. this.$set(taskData, 'focus', false);
  568. this.$set(taskData, 'title', '');
  569. //
  570. let tempId = $A.randomString(16);
  571. taskData.lists.unshift({
  572. id: tempId,
  573. title: title,
  574. loadIng: true,
  575. });
  576. this.taskSortDisabled = true;
  577. $A.apiAjax({
  578. url: 'project/task/add',
  579. data: {
  580. title: title,
  581. level: index,
  582. },
  583. complete: () => {
  584. this.taskSortDisabled = false;
  585. },
  586. error: () => {
  587. taskData.lists.some((item, i) => {
  588. if (item.id == tempId) {
  589. taskData.lists.splice(i, 1);
  590. return true;
  591. }
  592. });
  593. alert(this.$L('网络繁忙,请稍后再试!'));
  594. },
  595. success: (res) => {
  596. if (res.ret === 1) {
  597. this.$Message.success(res.msg);
  598. } else {
  599. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  600. }
  601. taskData.lists.some((item, i) => {
  602. if (item.id == tempId) {
  603. if (res.ret === 1) {
  604. taskData.lists.splice(i, 1, res.data);
  605. } else {
  606. taskData.lists.splice(i, 1);
  607. }
  608. return true;
  609. }
  610. });
  611. this.taskSortData = this.getTaskSort();
  612. }
  613. });
  614. },
  615. getTaskSort() {
  616. let sortData = "",
  617. taskData = "";
  618. for (let level in this.taskDatas) {
  619. taskData = "";
  620. this.taskDatas[level].lists.forEach((task) => {
  621. if (taskData) taskData += "-";
  622. taskData += task.id;
  623. });
  624. if (sortData) sortData += ";";
  625. sortData += level + ":" + taskData;
  626. }
  627. return sortData;
  628. },
  629. handleTodo(event) {
  630. switch (event) {
  631. case 'calendar':
  632. case 'complete':
  633. case 'attention': {
  634. this.todoDrawerShow = true;
  635. this.todoDrawerTab = event;
  636. break;
  637. }
  638. case 'report': {
  639. this.todoReportDrawerShow = true;
  640. break;
  641. }
  642. }
  643. },
  644. taskSortUpdate() {
  645. let oldSort = this.taskSortData;
  646. let newSort = this.getTaskSort();
  647. if (oldSort == newSort) {
  648. return;
  649. }
  650. this.taskSortData = newSort;
  651. this.taskSortDisabled = true;
  652. $A.apiAjax({
  653. url: 'project/sort/todo',
  654. data: {
  655. oldsort: oldSort,
  656. newsort: newSort,
  657. },
  658. complete: () => {
  659. this.taskSortDisabled = false;
  660. },
  661. error: () => {
  662. this.refreshTask();
  663. alert(this.$L('网络繁忙,请稍后再试!'));
  664. },
  665. success: (res) => {
  666. if (res.ret === 1) {
  667. this.$Message.success(res.msg);
  668. } else {
  669. this.refreshTask();
  670. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  671. }
  672. }
  673. });
  674. },
  675. openTaskModal(taskDetail) {
  676. this.taskDetail(taskDetail);
  677. },
  678. },
  679. }
  680. </script>