myFullCalendar.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. <template>
  2. <div :style="type+'-calendar-container'">
  3. <div :class="type+ '-calendar-header'">
  4. <article class="calender-top">
  5. <div class="calender-top-control">
  6. <el-button-group>
  7. <el-button icon="el-icon-arrow-left" size="small" @click="callCalendarApi('prev')" />
  8. <el-button icon="el-icon-arrow-right" size="small" @click="callCalendarApi('next')" />
  9. </el-button-group>
  10. <el-button-group v-if="weekMonYear">
  11. <el-button type="primary" size="small" @click="callCalendarApi('changeView','dayGridMonth')">月</el-button>
  12. <el-button type="primary" size="small" @click="callCalendarApi('changeView','timeGridWeek')">周</el-button>
  13. <el-button type="primary" size="small" @click="callCalendarApi('changeView','timeGridDay')">日</el-button>
  14. </el-button-group>
  15. <el-button-group>
  16. <el-button type="primary" size="small" :class="todayClassName" @click="callCalendarApi('today')">今天</el-button>
  17. </el-button-group>
  18. </div>
  19. <div class="calender-top-title">{{ calendarTitle }}</div>
  20. <slot />
  21. </article>
  22. </div>
  23. <FullCalendar
  24. v-show="activeName === '1'"
  25. :id="type + '-calendar'"
  26. ref="fullCalendar"
  27. height="auto"
  28. :class="type + '-calendar'"
  29. default-view="dayGridMonth"
  30. theme-system="bootstrap"
  31. :header="false"
  32. :event-time-format="evnetTime"
  33. :custom-buttons="customButtons"
  34. :button-text="buttonText"
  35. locale="zh-cn"
  36. editable="false"
  37. droppable="false"
  38. selectable="true"
  39. event-color="rgba(64,157,254,0.6)"
  40. :display-event-time="false"
  41. :plugins="calendarPlugins"
  42. :weekends="calendarWeekends"
  43. :events="events"
  44. @select="select"
  45. @dateClick="dateClick"
  46. @eventClick="eventClick"
  47. @eventDrop="eventDrop"
  48. @datesRender="datesRender"
  49. />
  50. <!-- <calendar-dialog
  51. :title="calendarDialogProperty.title"
  52. :visible="calendarDialogProperty.visible"
  53. :data="calendarDialogProperty.data"
  54. @cancel="calendarDialogProperty.visible = false"
  55. @confirm="calendarDialogProperty.visible = false"
  56. />
  57. <delete-dialog
  58. :content="'是否删除当前日程'"
  59. :visible="deleteDialogVisible"
  60. @cancel="deleteDialogVisible = false"
  61. @confirm="deleteDialogVisible= false"
  62. /> -->
  63. </div>
  64. </template>
  65. <script>
  66. // import moment from 'moment'
  67. import FullCalendar from '@fullcalendar/vue'
  68. import dayGridPlugin from '@fullcalendar/daygrid'
  69. import timeGridPlugin from '@fullcalendar/timegrid'
  70. import interactionPlugin from '@fullcalendar/interaction'
  71. import bootstrapPlugin from '@fullcalendar/bootstrap'
  72. import listPlugin from '@fullcalendar/list'
  73. import '@fullcalendar/core/main.css'
  74. import '@fullcalendar/daygrid/main.css'
  75. import '@fullcalendar/timegrid/main.css'
  76. import '@fullcalendar/bootstrap/main.css'
  77. import '@fullcalendar/list/main.css'
  78. // import CalendarDialog from './calendarFormDialog'
  79. // import DeleteDialog from '@/components/dialog/delete.vue'
  80. export default {
  81. components: {
  82. FullCalendar
  83. // CalendarDialog,
  84. // DeleteDialog
  85. },
  86. props: {
  87. type: {
  88. type: String,
  89. default: 'small',
  90. required: false
  91. },
  92. events: {
  93. type: Array,
  94. default: () => [],
  95. required: false
  96. },
  97. weekMonYear: {
  98. type: Boolean,
  99. default: false,
  100. required: false
  101. }
  102. },
  103. data() {
  104. return {
  105. activeName: '1',
  106. today: new Date(),
  107. todayClassName: 'today',
  108. evnetTime: {
  109. hour: 'numeric',
  110. minute: '2-digit',
  111. hour12: false
  112. },
  113. header: {
  114. left: 'prev,next today',
  115. center: 'title',
  116. right: 'dayGridMonth,timeGridWeek,timeGridDay amplify'
  117. },
  118. buttonText: {
  119. today: '今天',
  120. month: '月',
  121. week: '周',
  122. day: '日'
  123. },
  124. customButtons: {
  125. amplify: {
  126. text: '放大',
  127. bootstrapFontAwesome: 'fa-expand',
  128. click: function() {
  129. alert('点击了自定义按钮!')
  130. }
  131. }
  132. },
  133. calendarPlugins: [
  134. // plugins must be defined in the JS
  135. dayGridPlugin,
  136. timeGridPlugin,
  137. interactionPlugin, // needed for dateClick
  138. bootstrapPlugin,
  139. listPlugin
  140. ],
  141. calendarWeekends: true,
  142. deleteDialogVisible: false,
  143. calendarDialogProperty: {
  144. title: '新建日程',
  145. visible: false,
  146. data: null
  147. },
  148. calendarTitle: ''
  149. }
  150. },
  151. mounted() {
  152. this.callCalendarApi()
  153. },
  154. methods: {
  155. expand() {
  156. this.$emit('expand', true)
  157. },
  158. callCalendarApi(methods, viewName) {
  159. const calendarApi = this.$refs.fullCalendar.getApi()
  160. if (methods) {
  161. if (viewName) {
  162. calendarApi[methods](viewName)
  163. } else {
  164. calendarApi[methods]()
  165. }
  166. }
  167. this.$nextTick(() => {
  168. setTimeout(() => {
  169. this.setIcon()
  170. }, 2000)
  171. this.$emit('change', calendarApi.view)
  172. })
  173. this.calendarTitle = calendarApi.view.title
  174. if (calendarApi.view.activeStart.getTime() < this.today.getTime() && this.today.getTime() < calendarApi.view.activeEnd.getTime()) {
  175. this.todayClassName = 'today selected'
  176. } else {
  177. this.todayClassName = 'today'
  178. }
  179. },
  180. setIcon() {
  181. const eleList = document.getElementsByClassName('fc-title')
  182. Array.prototype.forEach.call(eleList, item => {
  183. // const grandParent = item.parentElement.parentElement
  184. // const color = grandParent.style.color
  185. const div = document.createElement('div')
  186. div.style.display = 'inline-block'
  187. div.style.paddingTop = '0'
  188. const icon = document.createElement('i')
  189. if (item.innerText.match(/排期/)) {
  190. item.innerText = item.innerText.replace(/排期:/, '')
  191. icon.className = 'el-icon-document'
  192. } else {
  193. item.innerText = item.innerText.replace(/日程:/, '')
  194. icon.className = 'el-icon-date'
  195. }
  196. div.appendChild(icon)
  197. item.parentElement.insertBefore(div, item)
  198. })
  199. },
  200. select(selectionInfo) { // 滑动多选时候返回的数据
  201. this.$emit('select', selectionInfo)
  202. },
  203. datesRender(arg) {
  204. // console.log(arg)
  205. },
  206. eventDrop(info) {
  207. this.$emit('eventDrop', info)
  208. },
  209. dateClick(arg) {
  210. this.$emit('dateClick', arg)
  211. // this.calendarDialogProperty.visible = true
  212. // this.calendarEvents.push({
  213. // title: '新增事件', start: arg.date, allDay: arg.allDay
  214. // })
  215. },
  216. eventClick(info) {
  217. this.$emit('eventClick', info)
  218. // alert('Event: ' + info.event.title)
  219. // info.el.style.borderColor = 'red'
  220. // info.el.style.backgroundColor = 'red'
  221. // this.deleteDialogVisible = true
  222. }
  223. }
  224. }
  225. </script>
  226. <style scoped lang="scss">
  227. >>>.el-tabs__nav-scroll{
  228. margin: 0 35px;
  229. }
  230. >>>.el-tabs__nav-wrap::after{
  231. height: 1px;
  232. }
  233. .calender-top {
  234. display: flex;
  235. height: 80px;
  236. align-items: center;
  237. justify-content: space-between;
  238. margin: 0 35px;
  239. .calender-top-title {
  240. font-size:16px;
  241. font-family:PingFangSC-Medium;
  242. color:rgba(51,59,74,1);
  243. }
  244. }
  245. >>>.fc-content {
  246. height: auto !important;
  247. display: flex;
  248. padding-top: 2px;
  249. }
  250. >>>.fc-title {
  251. line-height: 15px;
  252. padding-left: 4px;
  253. font-weight: bold !important;
  254. }
  255. >>>.fc-event-container .fc-content {
  256. text-overflow: inherit;
  257. }
  258. >>>.fc-day-grid-event .fc-content{
  259. white-space: normal;
  260. }
  261. >>>.fc-event {
  262. line-height: auto !important;
  263. }
  264. >>>.fc-day-header {
  265. height: 52px;
  266. line-height: 52px;
  267. }
  268. >>>#small-calendar .fc-dayGridMonth-view .table-bordered .fc-body .fc-day-number {
  269. transform: scale(1);
  270. font-size: 14px;
  271. }
  272. >>>#small-calendar .fc-view-container .table-bordered .fc-head .fc-day-header {
  273. transform: scale(1);
  274. font-size: 14px;
  275. }
  276. >>>.fc-scroller::-webkit-scrollbar {
  277. display:none !important;
  278. }
  279. >>>.fc-today {
  280. background-color: rgba(235,172,0,0.1);
  281. }
  282. >>>.fc th{
  283. border-color: #D8D8D8;
  284. }
  285. >>>.fc td {
  286. border-color: #D8D8D8;
  287. }
  288. </style>
  289. // fullcalendar
  290. <style lang='scss'>
  291. #small-calendar {
  292. margin: 0 35px 50px 35px;
  293. }
  294. #small-calendar .btn-primary {
  295. background-color: #fff;
  296. color: #6f7c93;
  297. border: 0.5px solid #bfc6dc;
  298. }
  299. #small-calendar .btn-primary:hover {
  300. background-color: #409eff;
  301. color: #fff;
  302. border: 0.5px solid #409eff;
  303. }
  304. #small-calendar .fc-today-button,
  305. .fc-dayGridMonth-button,
  306. .fc-timeGridWeek-button,
  307. .fc-timeGridDay-button {
  308. font-size: 10px !important;
  309. transform: scale(0.8333);
  310. padding: 5px !important;
  311. }
  312. #small-calendar .fc-timeGridWeek-button,
  313. .fc-timeGridDay-button {
  314. margin-left: -4px !important;
  315. }
  316. #small-calendar .fc-next-button {
  317. margin-left: -5px !important;
  318. }
  319. #small-calendar .fc-amplify-button {
  320. margin-right: -3px !important;
  321. }
  322. #small-calendar .fc-prev-button,
  323. .fc-next-button,
  324. .fc-amplify-button {
  325. font-size: 10px !important;
  326. transform: scale(0.8333);
  327. padding: 8px !important;
  328. }
  329. #small-calendar .fc-center h2 {
  330. font-size: 14px;
  331. font-weight: 500;
  332. }
  333. #small-calendar .fc-view-container .table-bordered .fc-head .fc-day-header {
  334. font-size: 10px;
  335. transform: scale(0.8333);
  336. }
  337. #small-calendar .fc-dayGridMonth-view .table-bordered .fc-body .fc-day-number {
  338. font-size: 8px;
  339. transform: scale(0.6667);
  340. }
  341. #small-calendar
  342. .fc-dayGridMonth-view
  343. .table-bordered
  344. .fc-body
  345. .fc-event-container
  346. .fc-content {
  347. height: 12px;
  348. width: 200%;
  349. margin-left: -49%;
  350. transform: scale(0.5);
  351. }
  352. #small-calendar
  353. .fc-dayGridMonth-view
  354. .table-bordered
  355. .fc-body
  356. .fc-event-container
  357. .fc-content
  358. span {
  359. font-size: 6px;
  360. display: inline-block;
  361. position: relative;
  362. bottom: 3px;
  363. }
  364. #small-calendar
  365. .fc-dayGridMonth-view
  366. .table-bordered
  367. .fc-body
  368. .fc-more {
  369. width: 125%;
  370. display: inline-block;
  371. position: relative;
  372. font-size: 6px;
  373. transform: scale(0.8);
  374. }
  375. #small-calendar
  376. .fc-more-popover {
  377. margin-top: 9%;
  378. margin-left: -14%;
  379. border-radius: 8px 8px 0 0;
  380. font-size: 6px;
  381. transform: scale(0.5);
  382. }
  383. #small-calendar
  384. .fc-more-popover
  385. .fc-body {
  386. height: 100px;
  387. overflow-y: auto;
  388. }
  389. #small-calendar
  390. .fc-more-popover
  391. .fc-header {
  392. background-color: #D8D8D8;
  393. }
  394. #small-calendar .fc-header-toolbar {
  395. margin-bottom: 10px;
  396. }
  397. #small-calendar .fc-timeGridWeek-view,
  398. .fc-timeGridDay-view {
  399. font-size: 12px;
  400. }
  401. </style>
  402. <style>
  403. #big-calendar {
  404. margin: auto;
  405. }
  406. #big-calendar
  407. .fc-more-popover
  408. .fc-header {
  409. background-color: #D8D8D8;
  410. }
  411. #big-calendar
  412. .fc-more-popover
  413. .fc-body {
  414. height: 222px;
  415. overflow-y: auto;
  416. }
  417. </style>
  418. <style>
  419. .fc-event-container .fc-content {
  420. text-overflow: ellipsis;
  421. }
  422. </style>