index.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 font40">{{ 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 { useStores, commonStores } from "@/store/modules/index";
  36. import { add, getStatus } from "@/api/business/zhaf/signIn.js";
  37. const commonStore = commonStores();
  38. const { proxy } = getCurrentInstance();
  39. const themeColor = computed(() => {
  40. return proxy.$settingStore.themeColor;
  41. });
  42. const state = reactive({
  43. address: "", //准确位置信息
  44. deviceCode: uni.getSystemInfoSync().deviceId, //设备编号
  45. signInType: 1, //签到类型(0:已签到 1:已签退)
  46. operateDate: commonStore.formatterDateTime(new Date()), //操作时间
  47. operateCode: 0, //操作类型
  48. longitude: "", //经度
  49. latitude: "", //纬度
  50. remarks: "", //备注
  51. });
  52. const inter = reactive({
  53. interLocation: null,
  54. interOperateDate: null,
  55. });
  56. function handleInsert() {
  57. add({
  58. deviceCode: state.deviceCode,
  59. signInType: state.signInType === 0 ? 1 : 0,
  60. operateCode: state.operateCode,
  61. longitude: state.longitude,
  62. latitude: state.latitude,
  63. remarks: state.remarks,
  64. }).then((res) => {
  65. if (res.status == "SUCCESS") {
  66. proxy.$modal.msgSuccess(state.signInType === 1 ? "签到成功" : "签退成功");
  67. getStatusApi(); //调用人员状态查询接口
  68. }
  69. });
  70. }
  71. /**
  72. * @人员状态查询
  73. * @接口查询
  74. */
  75. function getStatusApi() {
  76. getStatus().then((res) => {
  77. if (res.status == "SUCCESS" && res.data != null) {
  78. state.signInType = res.data.operateType;
  79. }
  80. });
  81. }
  82. function getLocation() {
  83. uni.getLocation({
  84. type: "gcj02",
  85. geocode: true,
  86. highAccuracyExpireTime: 5000,
  87. success: (res) => {
  88. console.log(res);
  89. state.longitude = res.longitude;
  90. state.latitude = res.latitude;
  91. state.address = res.address.city + res.address.district + res.address.street + res.address.streetNum + res.address.poiName;
  92. },
  93. fail: (res) => {
  94. console.log(res);
  95. },
  96. });
  97. }
  98. onLoad(() => {
  99. getStatusApi(); //调用人员状态查询接口
  100. //#ifdef APP-PLUS
  101. getLocation();
  102. inter.interLocation = setInterval(() => {
  103. getLocation();
  104. }, 1000 * 10);
  105. //#endif
  106. inter.interOperateDate = setInterval(() => {
  107. state.operateDate = commonStore.formatterDateTime(new Date());
  108. }, 1000);
  109. });
  110. onUnload(() => {
  111. //#ifdef APP-PLUS
  112. clearInterval(inter.interLocation); //销毁之前定时器
  113. //#endif
  114. clearInterval(inter.interOperateDate); //销毁之前定时器
  115. });
  116. onShow(() => {
  117. //调用系统主题颜色
  118. proxy.$settingStore.systemThemeColor([1]);
  119. });
  120. </script>
  121. <style lang="scss">
  122. .signIn {
  123. padding-top: 45%;
  124. //#ifdef MP-WEIXIN
  125. padding-top: 45%;
  126. //#endif
  127. &-button {
  128. width: 135px;
  129. height: 135px;
  130. text-align: center;
  131. margin: auto;
  132. }
  133. &-address {
  134. display: flex;
  135. justify-content: center;
  136. margin: auto;
  137. }
  138. }
  139. </style>