index.vue 4.3 KB

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