todo.vue 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  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. }, true);
  362. $A.setOnTaskInfoListener('pages/todo',(act, detail) => {
  363. switch (act) {
  364. case 'deleteproject': // 删除项目
  365. case 'deletelabel': // 删除分类
  366. this.refreshTask();
  367. return;
  368. case 'tasklevel':
  369. return;
  370. }
  371. //
  372. for (let level in this.taskDatas) {
  373. this.taskDatas[level].lists.some((task, i) => {
  374. if (task.id == detail.id) {
  375. this.taskDatas[level].lists.splice(i, 1, detail);
  376. return true;
  377. }
  378. });
  379. }
  380. //
  381. switch (act) {
  382. case "title": // 标题
  383. case "desc": // 描述
  384. case "plannedtime": // 设置计划时间
  385. case "unplannedtime": // 取消计划时间
  386. case "complete": // 标记完成
  387. case "unfinished": // 标记未完成
  388. case "comment": // 评论
  389. // 这些都不用处理
  390. break;
  391. case "level": // 优先级
  392. for (let level in this.taskDatas) {
  393. this.taskDatas[level].lists.some((task, i) => {
  394. if (task.id == detail.id) {
  395. this.taskDatas[level].lists.splice(i, 1);
  396. return true;
  397. }
  398. });
  399. if (level == detail.level) {
  400. this.taskDatas[level].lists.some((task, i) => {
  401. if (detail.userorder > task.userorder || (detail.userorder == task.userorder && detail.id > task.id)) {
  402. this.taskDatas[level].lists.splice(i, 0, detail);
  403. return true;
  404. }
  405. });
  406. }
  407. }
  408. this.taskSortData = this.getTaskSort();
  409. break;
  410. case "username": // 负责人
  411. case "delete": // 删除任务
  412. case "archived": // 归档
  413. for (let level in this.taskDatas) {
  414. this.taskDatas[level].lists.some((task, i) => {
  415. if (task.id == detail.id) {
  416. this.taskDatas[level].lists.splice(i, 1);
  417. return true;
  418. }
  419. });
  420. }
  421. this.taskSortData = this.getTaskSort();
  422. break;
  423. case "unarchived": // 取消归档
  424. for (let level in this.taskDatas) {
  425. if (level == detail.level) {
  426. this.taskDatas[level].lists.some((task, i) => {
  427. if (detail.userorder > task.userorder || (detail.userorder == task.userorder && detail.id > task.id)) {
  428. this.taskDatas[level].lists.splice(i, 0, detail);
  429. return true;
  430. }
  431. });
  432. }
  433. }
  434. this.taskSortData = this.getTaskSort();
  435. break;
  436. }
  437. }, true);
  438. },
  439. computed: {
  440. },
  441. watch: {
  442. },
  443. methods: {
  444. pTitle(p) {
  445. switch (p) {
  446. case "1":
  447. return "重要且紧急";
  448. case "2":
  449. return "重要不紧急";
  450. case "3":
  451. return "紧急不重要";
  452. case "4":
  453. return "不重要不紧急";
  454. }
  455. },
  456. refreshTask() {
  457. this.taskDatas = {
  458. "1": {lists: [], hasMorePages: false},
  459. "2": {lists: [], hasMorePages: false},
  460. "3": {lists: [], hasMorePages: false},
  461. "4": {lists: [], hasMorePages: false},
  462. };
  463. for (let i = 1; i <= 4; i++) {
  464. this.getTaskLists(i.toString());
  465. }
  466. },
  467. getTaskLists(index, isNext) {
  468. let taskData = this.taskDatas[index];
  469. let currentPage = 1;
  470. let pagesize = 20;
  471. let withNextPage = false;
  472. //
  473. if (isNext === true) {
  474. if (taskData.hasMorePages !== true) {
  475. return;
  476. }
  477. currentPage = Math.max(1, $A.runNum(taskData['currentPage']));
  478. let tempLists = this.taskDatas[detail.level].lists.filter((item) => { return item.complete == 0; });
  479. if (tempLists.length >= currentPage * pagesize) {
  480. currentPage++;
  481. } else {
  482. withNextPage = true;
  483. }
  484. }
  485. this.$set(taskData, 'hasMorePages', false);
  486. this.$set(taskData, 'loadIng', $A.runNum(taskData.loadIng) + 1);
  487. this.taskSortDisabled = true;
  488. this.loadIng++;
  489. $A.aAjax({
  490. url: 'project/task/lists',
  491. data: {
  492. level: index,
  493. sorts: {key:'userorder', order:'desc'},
  494. page: currentPage,
  495. pagesize: pagesize,
  496. },
  497. complete: () => {
  498. this.loadIng--;
  499. this.taskSortDisabled = false;
  500. this.$set(taskData, 'loadIng', $A.runNum(taskData.loadIng) - 1);
  501. },
  502. success: (res) => {
  503. if (res.ret === 1) {
  504. let inLists;
  505. res.data.lists.forEach((data) => {
  506. inLists = false;
  507. taskData.lists.some((item, i) => {
  508. if (item.id == data.id) {
  509. taskData.lists.splice(i, 1, data);
  510. return inLists = true;
  511. }
  512. });
  513. if (!inLists) {
  514. taskData.lists.push(data);
  515. }
  516. });
  517. this.taskSortData = this.getTaskSort();
  518. this.$set(taskData, 'currentPage', res.data.currentPage);
  519. this.$set(taskData, 'hasMorePages', res.data.hasMorePages);
  520. if (res.data.currentPage && withNextPage) {
  521. this.getTaskLists(index, true);
  522. }
  523. } else {
  524. this.$set(taskData, 'lists', []);
  525. this.$set(taskData, 'hasMorePages', false);
  526. }
  527. }
  528. });
  529. },
  530. addTask(index) {
  531. let taskData = this.taskDatas[index];
  532. let title = $A.trim(taskData.title);
  533. if ($A.count(title) == 0) {
  534. return;
  535. }
  536. this.$set(taskData, 'focus', false);
  537. this.$set(taskData, 'title', '');
  538. //
  539. let tempId = $A.randomString(16);
  540. taskData.lists.unshift({
  541. id: tempId,
  542. title: title,
  543. loadIng: true,
  544. });
  545. this.taskSortDisabled = true;
  546. $A.aAjax({
  547. url: 'project/task/add',
  548. data: {
  549. title: title,
  550. level: index,
  551. },
  552. complete: () => {
  553. this.taskSortDisabled = false;
  554. },
  555. error: () => {
  556. taskData.lists.some((item, i) => {
  557. if (item.id == tempId) {
  558. taskData.lists.splice(i, 1);
  559. return true;
  560. }
  561. });
  562. alert(this.$L('网络繁忙,请稍后再试!'));
  563. },
  564. success: (res) => {
  565. if (res.ret === 1) {
  566. this.$Message.success(res.msg);
  567. } else {
  568. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  569. }
  570. taskData.lists.some((item, i) => {
  571. if (item.id == tempId) {
  572. if (res.ret === 1) {
  573. taskData.lists.splice(i, 1, res.data);
  574. } else {
  575. taskData.lists.splice(i, 1);
  576. }
  577. return true;
  578. }
  579. });
  580. this.taskSortData = this.getTaskSort();
  581. }
  582. });
  583. },
  584. getTaskSort() {
  585. let sortData = "",
  586. taskData = "";
  587. for (let level in this.taskDatas) {
  588. taskData = "";
  589. this.taskDatas[level].lists.forEach((task) => {
  590. if (taskData) taskData += "-";
  591. taskData += task.id;
  592. });
  593. if (sortData) sortData += ";";
  594. sortData += level + ":" + taskData;
  595. }
  596. return sortData;
  597. },
  598. handleTodo(event) {
  599. switch (event) {
  600. case 'calendar':
  601. case 'complete':
  602. case 'attention': {
  603. this.todoDrawerShow = true;
  604. this.todoDrawerTab = event;
  605. break;
  606. }
  607. case 'report': {
  608. this.$Message.info("敬请期待!");
  609. break;
  610. }
  611. }
  612. },
  613. taskSortUpdate() {
  614. let oldSort = this.taskSortData;
  615. let newSort = this.getTaskSort();
  616. if (oldSort == newSort) {
  617. return;
  618. }
  619. this.taskSortData = newSort;
  620. this.taskSortDisabled = true;
  621. $A.aAjax({
  622. url: 'project/sort/todo',
  623. data: {
  624. oldsort: oldSort,
  625. newsort: newSort,
  626. },
  627. complete: () => {
  628. this.taskSortDisabled = false;
  629. },
  630. error: () => {
  631. this.refreshTask();
  632. alert(this.$L('网络繁忙,请稍后再试!'));
  633. },
  634. success: (res) => {
  635. if (res.ret === 1) {
  636. this.$Message.success(res.msg);
  637. $A.triggerTaskInfoListener('tasklevel', res.data.taskLevel);
  638. } else {
  639. this.refreshTask();
  640. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  641. }
  642. }
  643. });
  644. },
  645. openTaskModal(taskDetail) {
  646. this.taskDetail(taskDetail);
  647. },
  648. },
  649. }
  650. </script>