schedulePlan.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <template>
  2. <div id="home">
  3. <a-card title="我的计划" style="width: 100%">
  4. <p>
  5. <FullCalendar :options="calendarOptions" class="eventDeal-wrap" />
  6. <save-plan ref="savePlan" :fatherMethod="search" :fatherData="timeList"></save-plan>
  7. </p>
  8. </a-card>
  9. </div>
  10. </template>
  11. <script>
  12. import FullCalendar from '@fullcalendar/vue'
  13. import dayGridPlugin from '@fullcalendar/daygrid'
  14. import interactionPlugin from '@fullcalendar/interaction'
  15. import timeGridPlugin from '@fullcalendar/timegrid'
  16. import '@fullcalendar/daygrid/main.css'
  17. import SavePlan from './add/savePlan' // 子组件
  18. import { scheduleGetListByTime, scheduleQueryById } from '@api/oa/cd-schedule'
  19. // import { mapGetters } from 'vuex'
  20. // import { getAction } from '@/api/manage'
  21. // import '@fullcalendar/core/main.css'
  22. // import moment from 'moment'
  23. // import 'moment/locale/zh-cn'
  24. export default {
  25. name: 'SchedulePlan',
  26. components: {
  27. FullCalendar,
  28. SavePlan // 弹框 日程表单
  29. },
  30. data () {
  31. return {
  32. timeList: '', // 点击的时间
  33. // 日历参数
  34. calendarOptions: {
  35. // 日程数组
  36. events: [
  37. {
  38. title: 'Meeting',
  39. start: '2021-10-13T14:30:00',
  40. end: '2021-10-13T14:30:00',
  41. extendedProps: {
  42. status: 'done'
  43. },
  44. backgroundColor: 'orange',
  45. borderColor: 'none'
  46. }
  47. ],
  48. // 引入插件
  49. plugins: [dayGridPlugin, timeGridPlugin, interactionPlugin],
  50. // 日历头部按钮位置
  51. headerToolbar: {
  52. left: 'prev,next today',
  53. center: 'title',
  54. right: 'dayGridMonth, timeGridWeek, timeGridDay'
  55. },
  56. // 日历头部按钮中文转换
  57. buttonText: {
  58. today: '今天',
  59. month: '月',
  60. week: '周',
  61. day: '天'
  62. },
  63. initialView: 'dayGridMonth', // 指定默认显示视图
  64. locale: 'zh-ch', // 切换语言,当前为中文
  65. firstDay: '1', // 设置一周中显示的第一天是周几,周日是0,周一是1,以此类推
  66. weekNumberCalculation: 'ISO', // 与firstDay配套使用
  67. eventCOlor: '#3d8eec', // 全部日历日程背景色
  68. timeGridEventMinHeight: '20', // 设置事件的最小高度
  69. aspectRatio: '1.5', // 设置日历单元格宽高比
  70. displayEventTime: false, // 是否显示事件时间
  71. allDaySlot: false, // 周、日视图时,all-day不显示
  72. eventLimit: true, // 设置月日程,与all-day slot 的最大显示数量,超过的通过弹窗展示
  73. eventTimeFormat: {
  74. hour: 'numeric',
  75. minute: '2-digit',
  76. hour12: false
  77. },
  78. slotLabelFormat: {
  79. hour: '2-digit',
  80. minute: '2-digit',
  81. meridiem: false,
  82. hour12: false // 设置时间为24小时制
  83. },
  84. // 事件
  85. editable: true, // 是否可以进行(拖动、缩放)修改
  86. eventStartEditable: true, // Event日程开始时间可以改变,默认为true,若为false,则表示开始结束时间范围不能拉伸,只能拖拽
  87. eventDurationEditable: true, // Event日程的开始结束时间距离是否可以改变,默认为true,若为false,则表示开始结束时间范围不能拉伸,只能拖拽
  88. selectable: true, // 是否可以选中日历格
  89. selectMirror: true,
  90. selectMinDistance: 0, // 选中日历格的最小距离
  91. weekends: true,
  92. navLinks: true, // 天链接
  93. selectHelper: false,
  94. selectEventOverlap: false, // 相同时间段的多个日程视觉上是否允许重叠,默认为true,允许
  95. dayMaxEvents: true,
  96. dateClick: this.handleDateClick, // 日期点击
  97. eventsSet: this.handleEvents, // 事件点击
  98. eventClick: this.handleEventClick, // 日程点击信息展示
  99. eventDrop: this.handleEventDrop, // 日程拖动事件
  100. eventResize: this.eventResize // 日程缩放事件
  101. },
  102. selectDate: [], // 点击的日期
  103. data: {}, // 表单回显数据
  104. dateStr: '', // 点击日期回显的开始时间
  105. addForm: this.$form.createForm(this, { name: 'coordinated' })
  106. }
  107. },
  108. created () {
  109. this.search()
  110. },
  111. computed: {},
  112. mounted () {},
  113. methods: {
  114. // 点击日期
  115. handleDateClick (e) {
  116. const selectData = e.dateStr
  117. console.log('父组件点击的日期:', selectData)
  118. this.timeList = selectData
  119. // =====父组件拿子组件==================================
  120. // this.$refs.savePlan.formData.startTime = selectData
  121. // this.$refs.savePlan.formData.endTime = selectData
  122. // =====================================================
  123. this.$refs.savePlan.savePlanModalVisible = true
  124. this.$refs.savePlan.setStartTime() // 调用子组件回显日期方法
  125. },
  126. // 点击日程(回显)
  127. handleEventClick (e) {
  128. this.$refs.savePlan.savePlanModalVisible = true
  129. console.log('点击项ID', e.event.id)
  130. if (e.event.id) {
  131. // 根据id查询日程(注意接口文档传参格式要求)
  132. this.$nextTick(() => {
  133. scheduleQueryById({ id: e.event.id }).then(res => {
  134. if (res.success) {
  135. let formData = res.result // 查询结果赋值
  136. this.data = formData
  137. console.log('表单回显数据', this.data)
  138. this.$refs.savePlan.formData = this.data // 查询到的日程数据赋值给子组件表单
  139. this.$refs.savePlan.getFormInfo() // 调用子组件的回显数据
  140. }
  141. })
  142. })
  143. }
  144. },
  145. // 查询日程
  146. search () {
  147. scheduleGetListByTime(null).then(res => {
  148. if (res.success) {
  149. console.log('查询日程总', res)
  150. let list = res.result // 查询结果
  151. var eventList = [] // 日程事件集合
  152. // 循环日程
  153. list.forEach(e => {
  154. let Object = {
  155. title: e.title,
  156. start: e.startTime,
  157. end: e.endTime,
  158. id: e.id,
  159. backgroundColor: e.backgroundColor,
  160. extendedProps: {
  161. status: 'done'
  162. }
  163. }
  164. eventList.push(Object) // 把日程推到日程列表
  165. })
  166. // 刷新 日程列表
  167. this.calendarOptions.events = eventList
  168. }
  169. })
  170. },
  171. // 日程总集合
  172. handleEvents (info) {
  173. // console.log('总事件集合handleEvents.info:', info)
  174. // this.currentEvents = events
  175. },
  176. // 日程保存
  177. saveEvent (val) {
  178. let eventsArr = this.calendarOptions.events
  179. try {
  180. if (eventsArr.length === 0) {
  181. eventsArr.push(val)
  182. } else {
  183. eventsArr.forEach((item, index, eventsArr) => {
  184. // 若为修改日程
  185. if (item.eventID === val.eventID) {
  186. throw new Error(index)
  187. }
  188. })
  189. // 若为新增日程
  190. eventsArr.push(val)
  191. }
  192. } catch (e) {
  193. // 若为修改日程
  194. eventsArr.splice(e.message, 1, val)
  195. }
  196. },
  197. prev () {
  198. this.calendarApi.prev()
  199. console.log(this.calendarApi.prev)
  200. },
  201. // 日程删除
  202. deleteEvent (val) {
  203. let eventsArr = this.calendarOptions.events
  204. try {
  205. eventsArr.forEach((item, index, eventsArr) => {
  206. if (item.eventID === val) {
  207. throw new Error(index)
  208. }
  209. })
  210. } catch (e) {
  211. // 删除指定日程
  212. eventsArr.splice(parseInt(e.message), 1)
  213. }
  214. },
  215. handleWeekendsToggle () {
  216. console.log('handleWeekendsToggle')
  217. this.calendarOptions.weekends = !this.calendarOptions.weekends
  218. },
  219. // 日程事件触发
  220. eventClick (info) {
  221. console.log('eventClick.info:', info)
  222. info.el.style.borderColor = 'orange'
  223. },
  224. // 日程拖动事件
  225. handleEventDrop (info) {
  226. this.$refs['eventDialogue'].eventFormModel.start = info.event.start
  227. this.$refs['eventDialogue'].eventFormModel.end = info.event.end
  228. },
  229. // 日程缩放事件
  230. eventResize (info) {
  231. this.$refs['eventDialogue'].eventFormModel.start = info.event.start
  232. this.$refs['eventDialogue'].eventFormModel.end = info.event.end
  233. }
  234. }
  235. }
  236. </script>
  237. <style lang="less" scoped>
  238. /deep/ .ant-card-head-title {
  239. text-shadow: 1px 1px 2px rgb(170, 169, 169);
  240. color: #1890ff;
  241. }
  242. /deep/ .fc-daygrid-day-number {
  243. font-size: 20px !important;
  244. }
  245. /deep/ .fc-event-title {
  246. font-size: 14px !important;
  247. // white-space: break-spaces;
  248. }
  249. /deep/.fc-col-header>thead{
  250. height: 63px !important;
  251. line-height: 63px !important;
  252. background: #081f5b !important;
  253. }
  254. /deep/.fc-theme-standard td, .fc-theme-standard th{
  255. border: 1px solid #9ec3e0 !important;
  256. }
  257. /deep/.fc .fc-daygrid-day-top{
  258. flex-direction:column !important
  259. }
  260. /deep/.fc-daygrid-day-top>.fc-daygrid-day-number{
  261. color: #9178ba;
  262. font-size: 16px !important;
  263. }
  264. /deep/.fc .fc-col-header-cell-cushion{
  265. color: white;
  266. font-size: 16px;
  267. }
  268. /deep/.fc-event-title{
  269. color: #717171;
  270. }
  271. /deep/.fc .fc-daygrid-day.fc-day-today{
  272. background-color: white !important;
  273. }
  274. /deep/.fc-daygrid-event-dot{
  275. // border-color: #081f5b !important;
  276. }
  277. /deep/.fc .fc-toolbar-title{
  278. font-size: 30px !important;
  279. }
  280. /deep/.fc-event-title.fc-sticky{
  281. color: white;
  282. }
  283. /deep/.fc-scrollgrid-sync-table{
  284. height: 634px !important;
  285. }
  286. /deep/.fc-view-harness.fc-view-harness-active{
  287. height: 705.33px !important;
  288. // margin-left: 2%;
  289. }
  290. /deep/.fc .fc-scrollgrid, .fc .fc-scrollgrid table{
  291. width: 81% !important;
  292. margin-left: 8%;
  293. }
  294. /deep/.fc .fc-scrollgrid-section table{
  295. width: 100% !important;
  296. }
  297. /deep/.fc .fc-scrollgrid-section-body table, .fc .fc-scrollgrid-section-footer table{
  298. width: 100% !important;
  299. }
  300. /deep/ .fc .fc-toolbar.fc-header-toolbar{
  301. width: 81% !important;
  302. margin-left: 8%;
  303. }
  304. /deep/.fc .fc-view-harness-active > .fc-{
  305. display: flex;
  306. justify-content: center;
  307. }
  308. </style>