index.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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. fail(res) {
  109. // console.log(res)
  110. // uni.showToast({
  111. // icon:"none",
  112. // title:"获取位置失败"
  113. // })
  114. }
  115. });
  116. },
  117. creatDuty(){
  118. const self=this;
  119. uni.chooseImage({
  120. success(res) {
  121. self.onsubmit(res)
  122. },
  123. fail() {
  124. uni.showToast({
  125. icon:"none",
  126. title:"打卡失败"
  127. })
  128. }
  129. })
  130. // let filePath=e.tempFiles[0].url
  131. // let fileresq=await upload({filePath})
  132. },
  133. async onsubmit(res){
  134. let filePath=res.tempFiles[0].path
  135. let fileResq=await upload({filePath})
  136. let file=JSON.parse(fileResq).data
  137. creatDuty({
  138. dutyLocation:this.formData.dutyLocation,
  139. dutyPhoto:file.fileUrl,
  140. dutyIcon:file.fileIcon,
  141. dutyLongitude:this.formData.dutyLongitude,
  142. dutyLatitude:this.formData.dutyLongitude
  143. }).then(()=>{
  144. this.state=1
  145. }).catch(()=>{
  146. uni.showToast({
  147. icon:"none",
  148. title:"打卡失败"
  149. })
  150. })
  151. },
  152. chanegTab(idx){
  153. this.tabIdx=idx
  154. if(idx===2){
  155. this.getRecord()
  156. }
  157. },
  158. getRecord(){
  159. let dutyDate=parseTime(this.dutyDate,"{y}-{m}-{d}")
  160. getDutyRecord(dutyDate).then((res)=>{
  161. this.items=res.data
  162. })
  163. },
  164. previewImage(img){
  165. uni.previewImage({
  166. urls:[img]
  167. })
  168. }
  169. },
  170. onUnload() {
  171. clearInterval(this.timer)
  172. }
  173. }
  174. </script>
  175. <style lang="scss" scoped>
  176. .container{
  177. .tab{
  178. .tab-item{
  179. width: 50%;
  180. display: inline-block;
  181. padding: 0 100rpx;
  182. box-sizing: border-box;
  183. .text{
  184. height: 100rpx;
  185. line-height: 100rpx;
  186. text-align: center;
  187. color: rgba(33, 33, 33, 1);
  188. }
  189. &.active{
  190. .text{
  191. color: rgba(77, 115, 255, 1);
  192. }
  193. }
  194. }
  195. }
  196. .tab-content{
  197. background-color: rgba(245, 246, 248, 1);
  198. padding: 32rpx;
  199. .tab-wrap{
  200. background-color: #fff;
  201. min-height: calc(100vh - 170rpx);
  202. }
  203. .signIn{
  204. padding-top: 32rpx;
  205. .info{
  206. background-color: rgba(245, 246, 248, 1);
  207. width: 622rpx;
  208. margin: 0 auto;
  209. padding: 32rpx;
  210. box-sizing: border-box;
  211. .date{
  212. font-size: 30rpx;
  213. color:rgba(153, 153, 153, 1);
  214. .text{
  215. color: rgba(33, 33, 33, 1);
  216. }
  217. }
  218. .location{
  219. font-size: 30rpx;
  220. color:rgba(153, 153, 153, 1);
  221. .text{
  222. color: rgba(33, 33, 33, 1);
  223. }
  224. }
  225. }
  226. .signIn-handle{
  227. width: 300rpx;
  228. height: 300rpx;
  229. border-radius: 50%;
  230. display: flex;
  231. justify-content: center;
  232. align-items: center;
  233. flex-direction: column;
  234. margin: 180rpx auto;
  235. background-color: rgba(90, 125, 251, 1);
  236. box-shadow: 0px 4px 20px 0px rgba(77, 115, 255, 0.3);
  237. .name{
  238. font-size: 40rpx;
  239. color: #fff;
  240. }
  241. .signInTime{
  242. font-size: 30rpx;
  243. color: rgba(255, 255, 255, 0.7);
  244. }
  245. }
  246. }
  247. .list{
  248. background-color: rgba(245, 246, 248, 1);
  249. .item{
  250. margin-bottom: 20rpx;
  251. display: flex;
  252. align-items: center;
  253. background-color: #fff;
  254. padding: 30rpx;
  255. border-radius: 16rpx;
  256. .item-info{
  257. flex: 1;
  258. .location{
  259. font-weight: 400;
  260. font-size: 34rpx;
  261. color: rgba(33, 33, 33, 1);
  262. }
  263. .date{
  264. font-size: 24rpx;
  265. color: rgba(33, 33, 33, 1);
  266. padding-top: 24rpx;
  267. }
  268. }
  269. .item-icon-box{
  270. width: 228rpx;
  271. height: 152rpx;
  272. background-color: rgba(245, 246, 248, 1);
  273. .item-icon{
  274. display: block;
  275. width: 228rpx;
  276. height: 152rpx;
  277. }
  278. }
  279. }
  280. }
  281. }
  282. .alert{
  283. .mask{
  284. display: block;
  285. position: fixed;
  286. content: "";
  287. left: 0;
  288. right: 0;
  289. top: 0;
  290. bottom: 0;
  291. background-color: rgba(0,0,0,0.6);
  292. z-index: 99
  293. }
  294. .alert-wrap{
  295. width: 630rpx;
  296. height: 556rpx;
  297. background-color: #fff;
  298. position: fixed;
  299. left: 50%;
  300. top: 50%;
  301. transform: translate(-50%,-50%);
  302. z-index: 999;
  303. border-radius: 16rpx;
  304. display: flex;
  305. justify-content: center;
  306. align-items: center;
  307. flex-direction: column;
  308. .icon{
  309. width: 160rpx;
  310. }
  311. .tip{
  312. font-size: 48rpx;
  313. color: rgba(77, 115, 255, 1);
  314. font-weight: 600;
  315. padding: 22rpx 0 40rpx 0;
  316. }
  317. .button{
  318. width: 360rpx;
  319. height: 84rpx;
  320. text-align: center;
  321. line-height: 84rpx;
  322. color: rgba(77, 115, 255, 1);
  323. font-size: 30rpx;
  324. border: 1px solid rgba(77, 115, 255, 1);
  325. border-radius: 8rpx;
  326. }
  327. }
  328. }
  329. }
  330. </style>