index.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. <template>
  2. <view class="container">
  3. <view class="tab">
  4. <view class="tab-item" @click="chanegTab(1)" :class="tabIdx===1?'active':''">
  5. <view class="text">打卡签到</view>
  6. </view>
  7. <view class="tab-item" @click="chanegTab(2)" :class="tabIdx===2?'active':''">
  8. <view class="text">打卡记录</view>
  9. </view>
  10. </view>
  11. <view class="tab-content">
  12. <view class="tab-wrap">
  13. <view class="signIn" v-if="tabIdx===1">
  14. <view class="info">
  15. <view class="date">日期:<text class="text">{{signInDate}}</text></view>
  16. <view class="location">地点:<text class="text">{{formData.dutyLocation}}</text></view>
  17. </view>
  18. <view class="signIn-handle" @click="creatDuty">
  19. <view class="name">打卡</view>
  20. <view class="signInTime">{{signInTime}}</view>
  21. </view>
  22. </view>
  23. <view class="list" v-if="tabIdx===2">
  24. <!-- <view>
  25. <uni-calendar
  26. ref="calendar"
  27. :insert="false"
  28. @confirm="confirm"
  29. />
  30. <button @click="open">打开日历</button>
  31. </view> -->
  32. <view class="item" v-for="(item,index) in items" :key="index">
  33. <view class="item-info">
  34. <view class="location">
  35. <text>位置:</text>
  36. <text>{{item.dutyLocation}}</text>
  37. </view>
  38. <view class="date">{{item.dutyTime}}</view>
  39. </view>
  40. <view class="item-icon-box" @click="previewImage(item.dutyPhoto)">
  41. <img class="item-icon" :src="item.dutyIcon" alt="打卡图片">
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. <view class="alert success" v-if="state===1">
  48. <view class="mask">
  49. <view class="alert-wrap">
  50. <image class="icon" src="/static/face.png" mode="widthFix"></image>
  51. <view class="tip">打卡成功</view>
  52. <view class="button" @click="state=0">确定</view>
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. </template>
  58. <script>
  59. import {parseTime} from '@/utils/index.js';
  60. import { creatDuty} from '@/api/system/dutyApi.js';
  61. import { getDutyRecord} from '@/api/system/dutyApi.js';
  62. import {upload} from '@/api/system/upload.js';
  63. export default{
  64. data(){
  65. return{
  66. signInDate:parseTime(new Date(),'{y}-{m}-{d}'),
  67. signInTime:parseTime(new Date(),'{h}:{i}'),
  68. timer:null,
  69. tabIdx:1,
  70. state:0,
  71. dutyDate:new Date(),
  72. formData:{
  73. dutyLocation:"",
  74. dutyPhoto:"",
  75. dutyIcon:"",
  76. dutyLongitude:"",
  77. dutyLatitude:""
  78. },
  79. items:[]
  80. }
  81. },
  82. created() {
  83. let qrcode=uni.getStorageSync('qrcode')
  84. this.formData.dutyLocation=qrcode.targetTitle||"--"
  85. this.getLocation()
  86. this.setTime()
  87. },
  88. methods:{
  89. open(){
  90. this.$refs.calendar.open();
  91. },
  92. confirm(e) {
  93. console.log(e);
  94. },
  95. setTime(){
  96. this.timer=setInterval(()=>{
  97. this.signInTime=parseTime(new Date(),'{h}:{i}')
  98. },1000)
  99. },
  100. getLocation(){
  101. const self=this;
  102. uni.getLocation({
  103. type: 'wgs84',
  104. success: function (res) {
  105. self.formData.dutyLongitude=res.longitude
  106. self.formData.dutyLatitude=res.latitude
  107. }
  108. });
  109. },
  110. creatDuty(){
  111. const self=this;
  112. uni.chooseImage({
  113. sourceType: ['camera'],
  114. success(res) {
  115. self.onsubmit(res)
  116. },
  117. fail() {
  118. uni.showToast({
  119. icon:"none",
  120. title:"打卡失败"
  121. })
  122. }
  123. })
  124. },
  125. async onsubmit(res){
  126. let filePath=res.tempFiles[0].path
  127. let fileResq=await upload({filePath,formData:{
  128. additions: `经度:${this.formData.dutyLongitude};纬度:${this.formData.dutyLatitude}`
  129. }})
  130. let file=JSON.parse(fileResq).data
  131. creatDuty({
  132. dutyLocation:this.formData.dutyLocation,
  133. dutyPhoto:file.fileUrl,
  134. dutyIcon:file.fileIcon,
  135. dutyLongitude:this.formData.dutyLongitude,
  136. dutyLatitude:this.formData.dutyLatitude
  137. }).then(()=>{
  138. this.state=1
  139. }).catch(()=>{
  140. uni.showToast({
  141. icon:"none",
  142. title:"打卡失败"
  143. })
  144. })
  145. },
  146. chanegTab(idx){
  147. this.tabIdx=idx
  148. if(idx===2){
  149. this.getRecord()
  150. }
  151. },
  152. getRecord(){
  153. let dutyDate=parseTime(this.dutyDate,"{y}-{m}-{d}")
  154. getDutyRecord(dutyDate).then((res)=>{
  155. this.items=res.data
  156. })
  157. },
  158. previewImage(img){
  159. uni.previewImage({
  160. urls:[img]
  161. })
  162. }
  163. },
  164. onUnload() {
  165. clearInterval(this.timer)
  166. }
  167. }
  168. </script>
  169. <style lang="scss" scoped>
  170. .container{
  171. .tab{
  172. .tab-item{
  173. width: 50%;
  174. display: inline-block;
  175. padding: 0 100rpx;
  176. box-sizing: border-box;
  177. .text{
  178. height: 100rpx;
  179. line-height: 100rpx;
  180. text-align: center;
  181. color: rgba(33, 33, 33, 1);
  182. }
  183. &.active{
  184. .text{
  185. color: rgba(77, 115, 255, 1);
  186. }
  187. }
  188. }
  189. }
  190. .tab-content{
  191. background-color: rgba(245, 246, 248, 1);
  192. padding: 32rpx;
  193. .tab-wrap{
  194. background-color: #fff;
  195. min-height: calc(100vh - 170rpx);
  196. }
  197. .signIn{
  198. padding-top: 32rpx;
  199. .info{
  200. background-color: rgba(245, 246, 248, 1);
  201. width: 622rpx;
  202. margin: 0 auto;
  203. padding: 32rpx;
  204. box-sizing: border-box;
  205. .date{
  206. font-size: 30rpx;
  207. color:rgba(153, 153, 153, 1);
  208. .text{
  209. color: rgba(33, 33, 33, 1);
  210. }
  211. }
  212. .location{
  213. font-size: 30rpx;
  214. color:rgba(153, 153, 153, 1);
  215. .text{
  216. color: rgba(33, 33, 33, 1);
  217. }
  218. }
  219. }
  220. .signIn-handle{
  221. width: 300rpx;
  222. height: 300rpx;
  223. border-radius: 50%;
  224. display: flex;
  225. justify-content: center;
  226. align-items: center;
  227. flex-direction: column;
  228. margin: 180rpx auto;
  229. background-color: rgba(90, 125, 251, 1);
  230. box-shadow: 0px 4px 20px 0px rgba(77, 115, 255, 0.3);
  231. .name{
  232. font-size: 40rpx;
  233. color: #fff;
  234. }
  235. .signInTime{
  236. font-size: 30rpx;
  237. color: rgba(255, 255, 255, 0.7);
  238. }
  239. }
  240. }
  241. .list{
  242. background-color: rgba(245, 246, 248, 1);
  243. .item{
  244. margin-bottom: 20rpx;
  245. display: flex;
  246. align-items: center;
  247. background-color: #fff;
  248. padding: 30rpx;
  249. border-radius: 16rpx;
  250. .item-info{
  251. flex: 1;
  252. .location{
  253. font-weight: 400;
  254. font-size: 34rpx;
  255. color: rgba(33, 33, 33, 1);
  256. }
  257. .date{
  258. font-size: 24rpx;
  259. color: rgba(33, 33, 33, 1);
  260. padding-top: 24rpx;
  261. }
  262. }
  263. .item-icon-box{
  264. width: 228rpx;
  265. height: 152rpx;
  266. background-color: rgba(245, 246, 248, 1);
  267. .item-icon{
  268. display: block;
  269. width: 228rpx;
  270. height: 152rpx;
  271. }
  272. }
  273. }
  274. }
  275. }
  276. .alert{
  277. .mask{
  278. display: block;
  279. position: fixed;
  280. content: "";
  281. left: 0;
  282. right: 0;
  283. top: 0;
  284. bottom: 0;
  285. background-color: rgba(0,0,0,0.6);
  286. z-index: 99
  287. }
  288. .alert-wrap{
  289. width: 630rpx;
  290. height: 556rpx;
  291. background-color: #fff;
  292. position: fixed;
  293. left: 50%;
  294. top: 50%;
  295. transform: translate(-50%,-50%);
  296. z-index: 999;
  297. border-radius: 16rpx;
  298. display: flex;
  299. justify-content: center;
  300. align-items: center;
  301. flex-direction: column;
  302. .icon{
  303. width: 160rpx;
  304. }
  305. .tip{
  306. font-size: 48rpx;
  307. color: rgba(77, 115, 255, 1);
  308. font-weight: 600;
  309. padding: 22rpx 0 40rpx 0;
  310. }
  311. .button{
  312. width: 360rpx;
  313. height: 84rpx;
  314. text-align: center;
  315. line-height: 84rpx;
  316. color: rgba(77, 115, 255, 1);
  317. font-size: 30rpx;
  318. border: 1px solid rgba(77, 115, 255, 1);
  319. border-radius: 8rpx;
  320. }
  321. }
  322. }
  323. }
  324. </style>