WorkManage.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <template>
  2. <div class="work home">
  3. <view-header class="home-header"></view-header>
  4. <div class="home-body">
  5. <div class="home-main">
  6. <div class="part-box-head">
  7. <Form label-position="left" inline>
  8. <FormItem>
  9. <Input
  10. v-model.trim="modalForm.name"
  11. placeholder="工作名称"
  12. clearable
  13. ></Input>
  14. </FormItem>
  15. <FormItem :label-width="0">
  16. <Button
  17. size="small"
  18. type="success"
  19. icon="recode-white icon"
  20. shape="circle"
  21. @click="toAdd"
  22. >新增工作文件</Button
  23. >
  24. </FormItem>
  25. </Form>
  26. </div>
  27. <Table
  28. ref="TableList"
  29. :columns="columns"
  30. :data="works"
  31. :row-class-name="rowClassName"
  32. disabled-hover
  33. border
  34. ></Table>
  35. <view-footer></view-footer>
  36. </div>
  37. </div>
  38. </div>
  39. </template>
  40. <script>
  41. import { workList, createWork, activeWork, deleteWork } from "@/api";
  42. export default {
  43. name: "work",
  44. data() {
  45. return {
  46. modalForm: {
  47. name: ""
  48. },
  49. works: [],
  50. columns: [
  51. {
  52. title: "序号",
  53. width: 80,
  54. render: (h, param) => {
  55. return h("div", param.index + 1 + "");
  56. }
  57. },
  58. {
  59. title: "ID",
  60. key: "id",
  61. minWidth: 100
  62. },
  63. {
  64. title: "名称",
  65. key: "name",
  66. minWidth: 200
  67. },
  68. {
  69. title: "是否为当前工作",
  70. key: "active",
  71. minWidth: 200,
  72. render: (h, param) => {
  73. return h("div", param.row.active ? "是" : "否");
  74. }
  75. },
  76. {
  77. title: "创建时间",
  78. key: "createdOn",
  79. minWidth: 160
  80. },
  81. {
  82. title: "操作",
  83. key: "action",
  84. width: 140,
  85. align: "center",
  86. className: "table-action",
  87. render: (h, param) => {
  88. const actions = [
  89. {
  90. icon: "md-settings",
  91. classes: [{ "icon-act": param.row.active }],
  92. attrs: {
  93. title: "设置为当前工作"
  94. },
  95. action: () => {
  96. this.toActive(param.row);
  97. }
  98. },
  99. {
  100. icon: "md-trash",
  101. classes: ["icon-danger"],
  102. attrs: {
  103. title: "删除"
  104. },
  105. action: () => {
  106. this.toDelete(param.row);
  107. }
  108. },
  109. {
  110. icon: "md-arrow-round-forward",
  111. attrs: {
  112. title: "进入"
  113. },
  114. action: () => {
  115. this.toDetail(param.row);
  116. }
  117. }
  118. ];
  119. return h("div", this.$tableIconAction(h, actions));
  120. }
  121. }
  122. ]
  123. };
  124. },
  125. mounted() {
  126. this.getList();
  127. },
  128. methods: {
  129. async getList() {
  130. const data = await workList();
  131. this.works = data.map(item => {
  132. return {
  133. id: item.id,
  134. name: item.name,
  135. active: item.active,
  136. createdOn: item.createdOn
  137. };
  138. });
  139. },
  140. rowClassName(row) {
  141. return row.active ? "row-active" : "";
  142. },
  143. async toAdd() {
  144. if (!this.modalForm.name) {
  145. this.$Message.error("请输入工作名称!");
  146. return;
  147. }
  148. if (this.modalForm.name.length > 100) {
  149. this.$Message.error("工作名称长度不能超过100个字符!");
  150. return;
  151. }
  152. await createWork(this.modalForm);
  153. this.$Message.success("创建工作成功!");
  154. this.getList();
  155. },
  156. async toActive(row) {
  157. await activeWork(row.id);
  158. this.$Message.success("设置成功!");
  159. this.getList();
  160. },
  161. toDetail(row) {
  162. this.$router.push({
  163. name: "WorkOverview",
  164. params: {
  165. workId: row.id
  166. }
  167. });
  168. },
  169. toDelete(row) {
  170. this.$Modal.confirm({
  171. title: "删除警告",
  172. content: "确定要删除当前工作吗?",
  173. onOk: () => {
  174. this.toDel(row.id);
  175. }
  176. });
  177. },
  178. async toDel(id) {
  179. await deleteWork(id);
  180. this.$Message.success("删除成功!");
  181. this.getList();
  182. }
  183. }
  184. };
  185. </script>