calendar.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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.dispatch({
  188. type: "calendar/commActions",
  189. payload: {
  190. key: "messagesList",
  191. data: {
  192. pageNum: num,
  193. pageSize: 100,
  194. },
  195. },
  196. }).then((res)=>{
  197. if(res && res.list.length == 0){
  198. clearInterval(timer)
  199. }else if(res && res.list.length != 0){
  200. res.list.map((item)=>{
  201. if(!item.readStatus){
  202. this.messageType = true;
  203. return;
  204. }
  205. })
  206. }
  207. })
  208. num++;
  209. },100)
  210. }
  211. },
  212. };
  213. </script>
  214. <style lang="less">
  215. .calender-page {
  216. height: 100%;
  217. position: relative;
  218. .calender-remind {
  219. width: 62.5rpx;
  220. height: 62.5rpx;
  221. position: fixed;
  222. top: 12.5rpx;
  223. right: 25rpx;
  224. background: rgba(255, 255, 255, 0.95);
  225. border-radius: 50%;
  226. z-index: 2;
  227. image {
  228. margin-left: 17.5rpx;
  229. margin-top: 16.87rpx;
  230. width: 27.5rpx;
  231. height: 28.75rpx;
  232. }
  233. }
  234. .cheanged-time {
  235. padding: 25rpx 0rpx 15rpx 25rpx;
  236. font-size: 35rpx;
  237. .weekDay {
  238. padding-left: 15rpx;
  239. font-size: 20rpx;
  240. color: #666f80;
  241. }
  242. }
  243. .calendarTitle {
  244. background-color: #fff;
  245. display: inline-block;
  246. width: 14.286%;
  247. text-align: center;
  248. font-size: 20rpx;
  249. color: #666e80;
  250. line-height: 55rpx;
  251. }
  252. .calendarCon {
  253. margin-right: 1.25rpx;
  254. margin-top: 1.25rpx;
  255. height: 168.75rpx;
  256. background-color: #fff;
  257. float: left;
  258. width: 14.1%;
  259. text-align: center;
  260. font-size: 35rpx;
  261. color: #292c33;
  262. .date {
  263. margin: 16.25rpx auto 6.25rpx;
  264. height: 52.5rpx;
  265. width: 52.5rpx;
  266. line-height: 52.5rpx;
  267. border-radius: 50%;
  268. }
  269. .date2 {
  270. margin: 16.25rpx auto 6.25rpx;
  271. height: 52.5rpx;
  272. width: 52.5rpx;
  273. line-height: 52.5rpx;
  274. border-radius: 50%;
  275. background-color: #3377ff;
  276. color: #fff;
  277. }
  278. .yinDate {
  279. color: #666e80;
  280. font-size: 17.5rpx;
  281. line-height: 17.5rpx;
  282. }
  283. .work {
  284. width: 87.5rpx;
  285. height: 50rpx;
  286. background-color: #ff894d;
  287. border-radius: 5rpx;
  288. margin: 16.25rpx auto;
  289. .sum {
  290. font-size: 20rpx;
  291. color: #fff;
  292. font-weight: bold;
  293. line-height: 30rpx;
  294. }
  295. .danwei {
  296. font-weight: 400;
  297. font-size: 15rpx;
  298. color: #fff;
  299. line-height: 15rpx;
  300. }
  301. }
  302. }
  303. }
  304. </style>