cxTable.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. <template>
  2. <view class="content">
  3. <image src="../static/image/cxb.png" mode="widthFix" style="width: 100vw;"></image>
  4. <view class="table">
  5. <view class="row" v-for="(item,index) in tableList" :class="item.check?'row-active':''">
  6. <image src="../static/image/today.png" mode="widthFix" v-if="item.check" style="width: 34rpx;position: absolute;left: 5px;height: auto;"></image>
  7. <view class="col1 color">
  8. {{item.name}}
  9. </view>
  10. <view class="col2 col">
  11. {{item.val1}}
  12. </view>
  13. <view class="col3 col">
  14. {{item.val2}}
  15. </view>
  16. <view class="col4 col">
  17. {{item.val3}}
  18. </view>
  19. <view class="col5 col">
  20. {{item.val4}}
  21. </view>
  22. </view>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. export default {
  28. data() {
  29. return {
  30. isShowStyle:false,
  31. tableList: [{
  32. name: '日期/时间',
  33. val1: '涨潮',
  34. val2: '落潮',
  35. val3: '涨潮',
  36. val4: '落潮',
  37. check:false,
  38. },
  39. {
  40. name: '初一/十六',
  41. val1: '5:44',
  42. val2: '11:44',
  43. val3: '17:44',
  44. val4: '23:44',
  45. check:false,
  46. }, {
  47. name: '初二/十七',
  48. val1: '6:32',
  49. val2: '12:32',
  50. val3: '18:32',
  51. val4: '24:32',
  52. check:false,
  53. }, {
  54. name: '初三/十八',
  55. val1: '7:20',
  56. val2: '12:20',
  57. val3: '19:20',
  58. val4: '1:20',
  59. check:false,
  60. }, {
  61. name: '初四/十九',
  62. val1: '8:08',
  63. val2: '14:08',
  64. val3: '20:08',
  65. val4: '2:08',
  66. check:false,
  67. }, {
  68. name: '初五/二十',
  69. val1: '8:56',
  70. val2: '14:56',
  71. val3: '20:56',
  72. val4: '2:56',
  73. check:false,
  74. }, {
  75. name: '初六/廿一',
  76. val1: '9:44',
  77. val2: '15:44',
  78. val3: '21:44',
  79. val4: '3:44',
  80. check:false,
  81. }, {
  82. name: '初七/廿二',
  83. val1: '10:32',
  84. val2: '16:32',
  85. val3: '22:32',
  86. val4: '4:32',
  87. check:false,
  88. }, {
  89. name: '初八/廿三',
  90. val1: '11:20',
  91. val2: '17:20',
  92. val3: '23:20',
  93. val4: '5:20',
  94. check:false,
  95. }, {
  96. name: '初九/廿四',
  97. val1: '12:08',
  98. val2: '18:08',
  99. val3: '0:08',
  100. val4: '6:08',
  101. check:false,
  102. }, {
  103. name: '初十/廿五',
  104. val1: '12:56',
  105. val2: '18:56',
  106. val3: '0:56',
  107. val4: '6:56',
  108. check:false,
  109. }, {
  110. name: '十一/廿六',
  111. val1: '13:44',
  112. val2: '19:44',
  113. val3: '1:44',
  114. val4: '7:44',
  115. check:false,
  116. }, {
  117. name: '十二/廿七',
  118. val1: '14:32',
  119. val2: '20:32',
  120. val3: '2:32',
  121. val4: '8:32',
  122. check:false,
  123. }, {
  124. name: '十三/廿八',
  125. val1: '15:20',
  126. val2: '21:20',
  127. val3: '3:20',
  128. val4: '9:20',
  129. check:false,
  130. }, {
  131. name: '十四/廿九',
  132. val1: '16:08',
  133. val2: '22:08',
  134. val3: '4:08',
  135. val4: '10:08',
  136. check:false,
  137. }, {
  138. name: '十五/三十',
  139. val1: '17:56',
  140. val2: '23:56',
  141. val3: '5:56',
  142. val4: '10:56',
  143. check:false,
  144. }
  145. ],
  146. day:''
  147. }
  148. },
  149. onLoad() {
  150. this.getLunar()
  151. },
  152. methods: {
  153. setRowColor(){
  154. for(let i = 1;i<this.tableList.length;i++){
  155. this.tableList[i].false
  156. let _array = this.tableList[i].name.split("/")
  157. if(this.day==_array[0]||this.day==_array[1]){
  158. this.tableList[i+1].check = true
  159. }
  160. }
  161. },
  162. getLunar(){
  163. let that = this
  164. var nyear;
  165. var nmonth;
  166. var nday = -1;
  167. var nwday;
  168. var nhrs;
  169. var nmin;
  170. var nsec;
  171. var lmonth, lday, lleap; //农历参数
  172. function Draw() {
  173. NewTick();
  174. //显示时间
  175. var s = nyear + '年' + nmonth + '月' + nday + '日 ' + '星期' + cweekday(nwday) + ' ' + shapetime(nhrs, nmin, nsec);
  176. s += " 农历" + lmonth + "月" + lday; //农历
  177. that.day= lday;
  178. //需要展示在页面地方
  179. console.log("农历日期---",that.day);
  180. that.setRowColor()
  181. }
  182. function NewTick() {
  183. let noww = new Date();
  184. if (noww.getDate() != nday) {
  185. nyear = noww.getFullYear();
  186. nmonth = noww.getMonth() + 1;
  187. nwday = noww.getDay();
  188. nday = noww.getDate();
  189. getlunar(); //获取农历
  190. }
  191. nhrs = noww.getHours();
  192. nmin = noww.getMinutes();
  193. nsec = noww.getSeconds();
  194. }
  195. //辅助函数
  196. var hzWeek = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日");
  197. function cweekday(wday) {
  198. console.log('星期---',hzWeek[wday]);
  199. }
  200. function shapetime(vhrs, vmin, vsec) {
  201. if (vsec <= 9) vsec = "0" + vsec;
  202. if (vmin <= 9) vmin = "0" + vmin;
  203. if (vhrs <= 9) vhrs = "0" + vhrs;
  204. // return vhrs + ":" + vmin + ":" + vsec
  205. console.log("时间日期---",vhrs + ":" + vmin + ":" + vsec);
  206. }
  207. //阴历函数开始
  208. var lunarInfo = new Array(0x04bd8, 0x04ae0, 0x0a570, 0x054d5, 0x0d260, 0x0d950, 0x16554, 0x056a0, 0x09ad0, 0x055d2, 0x04ae0, 0x0a5b6, 0x0a4d0, 0x0d250, 0x1d255, 0x0b540, 0x0d6a0, 0x0ada2, 0x095b0, 0x14977, 0x04970, 0x0a4b0, 0x0b4b5, 0x06a50, 0x06d40, 0x1ab54, 0x02b60, 0x09570, 0x052f2, 0x04970, 0x06566, 0x0d4a0, 0x0ea50, 0x06e95, 0x05ad0, 0x02b60, 0x186e3, 0x092e0, 0x1c8d7, 0x0c950, 0x0d4a0, 0x1d8a6, 0x0b550, 0x056a0, 0x1a5b4, 0x025d0, 0x092d0, 0x0d2b2, 0x0a950, 0x0b557, 0x06ca0, 0x0b550, 0x15355, 0x04da0, 0x0a5b0, 0x14573, 0x052b0, 0x0a9a8, 0x0e950, 0x06aa0, 0x0aea6, 0x0ab50, 0x04b60, 0x0aae4, 0x0a570, 0x05260, 0x0f263, 0x0d950, 0x05b57, 0x056a0, 0x096d0, 0x04dd5, 0x04ad0, 0x0a4d0, 0x0d4d4, 0x0d250, 0x0d558, 0x0b540, 0x0b6a0, 0x195a6, 0x095b0, 0x049b0, 0x0a974, 0x0a4b0, 0x0b27a, 0x06a50, 0x06d40, 0x0af46, 0x0ab60, 0x09570, 0x04af5, 0x04970, 0x064b0, 0x074a3, 0x0ea50, 0x06b58, 0x05ac0, 0x0ab60, 0x096d5, 0x092e0, //1990
  209. 0x0c960, 0x0d954, 0x0d4a0, 0x0da50, 0x07552, 0x056a0, 0x0abb7, 0x025d0, 0x092d0, 0x0cab5, 0x0a950, 0x0b4a0, 0x0baa4, 0x0ad50, 0x055d9, 0x04ba0, 0x0a5b0, 0x15176, 0x052b0, 0x0a930, 0x07954, 0x06aa0, 0x0ad50, 0x05b52, 0x04b60, 0x0a6e6, 0x0a4e0, 0x0d260, 0x0ea65, 0x0d530, 0x05aa0, 0x076a3, 0x096d0, 0x04bd7, 0x04ad0, 0x0a4d0, 0x1d0b6, 0x0d250, 0x0d520, 0x0dd45, 0x0b5a0, 0x056d0, 0x055b2, 0x049b0, 0x0a577, 0x0a4b0, 0x0aa50, 0x1b255, 0x06d20, 0x0ada0, 0x14b63);
  210. function lYearDays(y) {
  211. var i, sum = 348;
  212. for (i = 0x8000; i > 0x8; i >>= 1) sum += (lunarInfo[y - 1900] & i) ? 1 : 0;
  213. return (sum + leapDays(y));
  214. }
  215. function leapDays(y) {
  216. if (leapMonth(y)) return ((lunarInfo[y - 1900] & 0x10000) ? 30 : 29);
  217. else return (0);
  218. }
  219. function leapMonth(y) {
  220. return (lunarInfo[y - 1900] & 0xf);
  221. }
  222. function monthDays(y, m) {
  223. return ((lunarInfo[y - 1900] & (0x10000 >> m)) ? 30 : 29);
  224. }
  225. function Lunar(y, m, d) {
  226. var i, leap = 0,
  227. temp = 0;
  228. var offset = (Date.UTC(y, m, d) - Date.UTC(1900, 0, 31)) / 86400000;
  229. for (i = 1900; i < 2050 && offset > 0; i++) {
  230. temp = lYearDays(i);
  231. offset -= temp;
  232. }
  233. if (offset < 0) {
  234. offset += temp;
  235. i--;
  236. }
  237. this.year = i;
  238. leap = leapMonth(i);
  239. this.isLeap = false;
  240. for (i = 1; i < 13 && offset > 0; i++) {
  241. if (leap > 0 && i == (leap + 1) && this.isLeap == false) {--i;
  242. this.isLeap = true;
  243. temp = leapDays(this.year);
  244. } else {
  245. temp = monthDays(this.year, i);
  246. }
  247. if (this.isLeap == true && i == (leap + 1)) this.isLeap = false;
  248. offset -= temp;
  249. }
  250. if (offset == 0 && leap > 0 && i == leap + 1) if (this.isLeap) {
  251. this.isLeap = false;
  252. } else {
  253. this.isLeap = true; --i;
  254. }
  255. if (offset < 0) {
  256. offset += temp; --i;
  257. }
  258. this.month = i;
  259. this.day = offset + 1;
  260. }
  261. var nStr1 = new Array('', '一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二');
  262. var nStr2 = new Array('初', '十', '廿', '卅', '□');
  263. function GetcDay(d) {
  264. var s;
  265. switch (d) {
  266. case 10:
  267. s = '初十';
  268. break;
  269. case 20:
  270. s = '二十';
  271. break;
  272. case 30:
  273. s = '三十';
  274. break;
  275. default:
  276. s = nStr2[Math.floor(d / 10)];
  277. s += nStr1[d % 10];
  278. break;
  279. }
  280. return (s);
  281. }
  282. function GetcMon(m) {
  283. if (m == 1) return '正';
  284. else return nStr1[m];
  285. }
  286. function getlunar() {
  287. var lObj = new Lunar(nyear, nmonth - 1, nday);
  288. lmonth = GetcMon(lObj.month);
  289. lday = GetcDay(lObj.day);
  290. lleap = lObj.isLeap;
  291. if (lleap == 1) {
  292. lmonth = "闰" + lmonth;
  293. }
  294. }
  295. //阴历函数结束
  296. Draw();
  297. },
  298. }
  299. }
  300. </script>
  301. <style scoped lang="scss">
  302. .content {
  303. position: relative;
  304. .table {
  305. position: absolute;
  306. top: 170rpx;
  307. padding: 20rpx 0;
  308. width: 90%;
  309. right: 0;
  310. left: 0;
  311. margin: auto;
  312. .row {
  313. display: flex;
  314. justify-content: space-around;
  315. align-items: center;
  316. .col1 {
  317. width: 40%;
  318. display: flex;
  319. justify-content: center;
  320. }
  321. .col{
  322. width: 20%;
  323. display: flex;
  324. justify-content: center;
  325. }
  326. }
  327. .row:nth-of-type(2n){
  328. background: rgba(255, 255, 255, 0.6);
  329. padding: 6rpx 0;
  330. }
  331. .row:nth-of-type(2n+1){
  332. background: rgba(214, 214, 214, 0.7);
  333. padding: 6rpx 0;
  334. }
  335. .row:nth-of-type(1){
  336. padding: 18rpx 0;
  337. }
  338. }
  339. .row-active{
  340. background: #92b8f1!important;
  341. }
  342. }
  343. </style>