calendar.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <template>
  2. <view class="calender-page">
  3. <view class="calender-remind" @click="toMessagePage">
  4. <image
  5. :src="
  6. messageType
  7. ? '/static/message-unread.png'
  8. : '/static/message-read.png'
  9. "
  10. mode=""
  11. ></image>
  12. </view>
  13. <view class="cheanged-time" @click="clickTile"
  14. >{{ changedYear }}年{{ changedMonth }}月
  15. <!-- <text class="weekDay">{{changedDay}}</text> -->
  16. </view>
  17. <view>
  18. <text v-for="item in dayArray1" class="calendarTitle">{{ item }}</text>
  19. </view>
  20. <view>
  21. <view v-for="item in data1">
  22. <!-- {{item}} -->
  23. <view
  24. v-for="(items, index) in item"
  25. class="calendarCon"
  26. @click="dateClick(items, index)"
  27. :style="items.greyFlag ? { color: '#B8BECC' } : { color: '#292C33' }"
  28. >
  29. <view :class="items.specificDate == changedDate ? 'date2' : 'date'">
  30. {{ items.day ? items.day : "" }}
  31. </view>
  32. <view
  33. class="yinDate"
  34. :style="
  35. items.greyFlag ? { color: '#B8BECC' } : { color: '#292C33' }
  36. "
  37. >
  38. {{ items.chineseDay ? items.chineseDay : "" }}
  39. </view>
  40. <view :class="items.deptCount != '0' ? 'work' : ''">
  41. <view class="sum">{{
  42. items.deptCount != "0" ? items.deptCount : ""
  43. }}</view>
  44. <view class="danwei">{{
  45. items.deptCount != "0" ? "单位" : ""
  46. }}</view>
  47. </view>
  48. </view>
  49. </view>
  50. </view>
  51. <change-calendar
  52. v-if="showCC"
  53. :changedYear="changedYear"
  54. :changedMonth="changedMonth"
  55. @cancelCC="cancelCC"
  56. @sureCC="sureCC"
  57. ></change-calendar>
  58. <tm-tabbar />
  59. </view>
  60. </template>
  61. <script>
  62. import websocket from "../../utils/ws.js"; //引入websocket
  63. import {wsURL} from "../../utils/requestUrl.js";
  64. import moment from "moment";
  65. import changeCalendar from "./components/changeCalendar.vue";
  66. export default {
  67. data() {
  68. return {
  69. refTimer: null,
  70. isInitWs: null,
  71. messageType: null,
  72. dayArray: ["周日", "周一", "周二", "周三", "周四", "周五", "周六"],
  73. dayArray1: ["日", "一", "二", "三", "四", "五", "六"],
  74. days_per_month: [],
  75. changedYear: moment().format("YYYY"),
  76. changedMonth: moment().format("MM"),
  77. changedDay: "",
  78. showCC: false,
  79. firstday: "",
  80. dayOfWeek: "",
  81. str_nums: "",
  82. data1: [],
  83. changedDate: moment().format("YYYY-MM-DD"),
  84. };
  85. },
  86. components: {
  87. changeCalendar,
  88. },
  89. created() {
  90. this.changedDay = this.dayArray[new Date().getDay()];
  91. this.init(true);
  92. this.refTimer = setInterval(() => {
  93. this.isInitWs = websocket.ws ? false : true;
  94. this.init(this.isInitWs);
  95. }, 3 * 60 * 1000);
  96. // this.messStatus();
  97. },
  98. beforeDestroy() {
  99. // 关闭ws连接
  100. websocket.close();
  101. clearInterval(this.refTimer);
  102. },
  103. // watch: {
  104. // $route: {
  105. // handler(route) {
  106. // this.messStatus();
  107. // },
  108. // },
  109. // },
  110. methods: {
  111. getCanList() {
  112. this.$store
  113. .dispatch({
  114. type: "calendar/commActions",
  115. payload: {
  116. key: "getCalList",
  117. data: {
  118. years: this.changedYear + "-" + this.changedMonth,
  119. },
  120. },
  121. })
  122. .then((data) => {
  123. if (data) {
  124. let hiId = uni.getStorageSync("hiId");
  125. let user = uni.getStorageSync("id");
  126. let permission = uni.getStorageSync("nowPermission");
  127. this.isInitWs && this.initWebsocket(hiId, user, permission);
  128. this.str_nums = Math.ceil(data.length / 7); //确定日期表格所需的行数
  129. let data2 = [];
  130. for (let i = 0; i < this.str_nums; i++) {
  131. data2[i] = [];
  132. data2[i] = data.splice(0, 7);
  133. }
  134. this.data1 = data2;
  135. }
  136. });
  137. },
  138. init(isInitWs) {
  139. this.isInitWs = isInitWs;
  140. this.getCanList();
  141. },
  142. initWebsocket(hiId, user, permission) {
  143. websocket.url = wsURL(hiId, user, permission);
  144. websocket.createWebSocket(this.resolverWsData.bind(this));
  145. },
  146. // 解析websocket返回数据
  147. resolverWsData(type) {
  148. let types = JSON.parse(type);
  149. switch (types.type) {
  150. case "TO_READ":
  151. this.messageType = true;
  152. break;
  153. default:
  154. this.messageType = false;
  155. break;
  156. }
  157. },
  158. toMessagePage() {
  159. // this.messageType = false;
  160. uni.navigateTo({
  161. url: `/pages/messages/messages`,
  162. });
  163. },
  164. clickTile() {
  165. this.showCC = true;
  166. },
  167. cancelCC(data) {
  168. this.showCC = data;
  169. },
  170. sureCC(data, year, month) {
  171. this.showCC = data;
  172. this.changedYear = year;
  173. this.changedMonth = month;
  174. let day = year + "-" + month + "-01";
  175. this.changedDay = this.dayArray[new Date(day).getDay()];
  176. this.getCanList();
  177. },
  178. dateClick(data, i) {
  179. if (data && data.specificDate) {
  180. uni.navigateTo({
  181. url: `/pages/todayCheck/todayCheck?date=${data.specificDate}`,
  182. });
  183. }
  184. },
  185. // messStatus() {
  186. // let num = 1;
  187. // let timer = setInterval(() => {
  188. // this.$store
  189. // .dispatch({
  190. // type: "calendar/commActions",
  191. // payload: {
  192. // key: "messagesList",
  193. // data: {
  194. // pageNum: num,
  195. // pageSize: 100,
  196. // },
  197. // },
  198. // })
  199. // .then((res) => {
  200. // if (res && res.list.length == 0) {
  201. // clearInterval(timer);
  202. // } else if (res && res.list.length != 0) {
  203. // res.list.map((item) => {
  204. // if (!item.readStatus) {
  205. // this.messageType = true;
  206. // return;
  207. // }
  208. // });
  209. // }
  210. // });
  211. // num++;
  212. // }, 100);
  213. // },
  214. },
  215. };
  216. </script>
  217. <style lang="less">
  218. .calender-page {
  219. height: 100%;
  220. position: relative;
  221. .calender-remind {
  222. width: 62.5rpx;
  223. height: 62.5rpx;
  224. position: fixed;
  225. top: 12.5rpx;
  226. right: 25rpx;
  227. background: rgba(255, 255, 255, 0.95);
  228. border-radius: 50%;
  229. z-index: 2;
  230. image {
  231. margin-left: 17.5rpx;
  232. margin-top: 16.87rpx;
  233. width: 27.5rpx;
  234. height: 28.75rpx;
  235. }
  236. }
  237. .cheanged-time {
  238. padding: 25rpx 0rpx 15rpx 25rpx;
  239. font-size: 35rpx;
  240. .weekDay {
  241. padding-left: 15rpx;
  242. font-size: 20rpx;
  243. color: #666f80;
  244. }
  245. }
  246. .calendarTitle {
  247. background-color: #fff;
  248. display: inline-block;
  249. width: 14.286%;
  250. text-align: center;
  251. font-size: 20rpx;
  252. color: #666e80;
  253. line-height: 55rpx;
  254. border-bottom: 1.25rpx solid #f5f6fa;
  255. }
  256. .calendarCon {
  257. // margin-right: 1.25rpx;
  258. // margin-top: 1.25rpx;
  259. height: 168.75rpx;
  260. background-color: #fff;
  261. float: left;
  262. width: 14.2857%;
  263. text-align: center;
  264. font-size: 35rpx;
  265. color: #292c33;
  266. border-right: 1.25rpx solid #f5f6fa;
  267. border-bottom: 1.25rpx solid #f5f6fa;
  268. .date {
  269. margin: 16.25rpx auto 6.25rpx;
  270. height: 52.5rpx;
  271. width: 52.5rpx;
  272. line-height: 52.5rpx;
  273. border-radius: 50%;
  274. }
  275. .date2 {
  276. margin: 16.25rpx auto 6.25rpx;
  277. height: 52.5rpx;
  278. width: 52.5rpx;
  279. line-height: 52.5rpx;
  280. border-radius: 50%;
  281. background-color: #3377ff;
  282. color: #fff;
  283. }
  284. .yinDate {
  285. color: #666e80;
  286. font-size: 17.5rpx;
  287. line-height: 17.5rpx;
  288. }
  289. .work {
  290. width: 87.5rpx;
  291. height: 50rpx;
  292. background-color: #ff894d;
  293. border-radius: 5rpx;
  294. margin: 16.25rpx auto;
  295. .sum {
  296. font-size: 20rpx;
  297. color: #fff;
  298. font-weight: bold;
  299. line-height: 30rpx;
  300. }
  301. .danwei {
  302. font-weight: 400;
  303. font-size: 15rpx;
  304. color: #fff;
  305. line-height: 15rpx;
  306. }
  307. }
  308. }
  309. }
  310. </style>