todo.vue 24 KB

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