calendar.vue 7.8 KB

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