todo.vue 29 KB

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