index.vue 7.3 KB

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