index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <oa-scroll
  3. customClass="scroll-height"
  4. :refresherLoad="false"
  5. :refresherEnabled="false"
  6. :refresherDefaultStyle="'none'"
  7. :refresherThreshold="44"
  8. :refresherBackground="'#f5f6f7'"
  9. :data-theme="'theme-' + proxy.$settingStore.themeColor.name"
  10. >
  11. <template #default>
  12. <view class="signIn">
  13. <view
  14. class="signIn-button round mb30"
  15. :class="`bg-${themeColor.name}`"
  16. :style="{
  17. background: state.signInType === 1 ? themeColor.color : '#999999',
  18. }"
  19. @click="handleInsert()"
  20. >
  21. <view class="pt40 font20">{{ state.signInType === 1 ? "签到" : "签退" }}</view>
  22. <view class="mt5">{{ state.operateDate.split(" ")[1] }}</view>
  23. </view>
  24. <view class="signIn-address" v-if="state.address">
  25. <view class="iconfont oaIcon-address icon mt2" :class="`text-${themeColor.name}`"></view>
  26. <view class="ml5">{{ state.address }}</view>
  27. </view>
  28. </view>
  29. </template>
  30. </oa-scroll>
  31. </template>
  32. <script setup>
  33. import { onLoad, onShow, onHide, onLaunch, onUnload } from "@dcloudio/uni-app";
  34. import { ref, reactive, computed, onMounted, getCurrentInstance, toRefs, inject } from "vue";
  35. import { add, getStatus } from "@/api/business/zhaf/signIn.js";
  36. const { proxy } = getCurrentInstance();
  37. const themeColor = computed(() => {
  38. return proxy.$settingStore.themeColor;
  39. });
  40. const state = reactive({
  41. address: "", //准确位置信息
  42. deviceCode: uni.getSystemInfoSync().deviceId, //设备编号
  43. signInType: 1, //签到类型(0:已签到 1:已签退)
  44. operateDate: proxy.$common.formatterDateTime(new Date()), //操作时间
  45. operateCode: 0, //操作类型
  46. longitude: "", //经度
  47. latitude: "", //纬度
  48. remarks: "", //备注
  49. });
  50. const inter = reactive({
  51. interLocation: null,
  52. interOperateDate: null,
  53. });
  54. function handleInsert() {
  55. add({
  56. deviceCode: state.deviceCode,
  57. signInType: state.signInType === 0 ? 1 : 0,
  58. operateCode: state.operateCode,
  59. longitude: state.longitude,
  60. latitude: state.latitude,
  61. remarks: state.remarks,
  62. }).then((res) => {
  63. if (res.status == "SUCCESS") {
  64. proxy.$modal.msgSuccess(state.signInType === 1 ? "签到成功" : "签退成功");
  65. getStatusApi(); //调用人员状态查询接口
  66. }
  67. });
  68. }
  69. /**
  70. * @人员状态查询
  71. * @接口查询
  72. */
  73. function getStatusApi() {
  74. getStatus().then((res) => {
  75. if (res.status == "SUCCESS" && res.data != null) {
  76. state.signInType = res.data.operateType;
  77. }
  78. });
  79. }
  80. function getLocation() {
  81. uni.getLocation({
  82. type: "gcj02",
  83. geocode: true,
  84. highAccuracyExpireTime: 5000,
  85. success: (res) => {
  86. console.log(res);
  87. state.longitude = res.longitude;
  88. state.latitude = res.latitude;
  89. state.address = res.address.city + res.address.district + res.address.street + res.address.streetNum + res.address.poiName;
  90. },
  91. fail: (res) => {
  92. console.log(res);
  93. },
  94. });
  95. }
  96. onLoad(() => {
  97. getStatusApi(); //调用人员状态查询接口
  98. //#ifdef APP-PLUS
  99. inter.interLocation = setInterval(getLocation(), 1000 * 10);
  100. //#endif
  101. inter.interOperateDate = setInterval(() => {
  102. state.operateDate = proxy.$common.formatterDateTime(new Date());
  103. }, 1000);
  104. });
  105. onUnload(() => {
  106. //#ifdef APP-PLUS
  107. clearInterval(inter.interLocation); //销毁之前定时器
  108. //#endif
  109. clearInterval(inter.interOperateDate); //销毁之前定时器
  110. });
  111. onShow(() => {
  112. //调用系统主题颜色
  113. proxy.$settingStore.systemThemeColor([1]);
  114. });
  115. </script>
  116. <style lang="scss">
  117. .signIn {
  118. padding-top: 45%;
  119. //#ifdef MP-WEIXIN
  120. padding-top: 45%;
  121. //#endif
  122. &-button {
  123. width: 135px;
  124. height: 135px;
  125. text-align: center;
  126. margin: auto;
  127. }
  128. &-address {
  129. display: flex;
  130. justify-content: center;
  131. margin: auto;
  132. }
  133. }
  134. </style>