punchLocation.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <template>
  2. <view class="container">
  3. <!-- 头部添加打卡时间区域 -->
  4. <view class="add">
  5. <view class="icon" @click="handleAdd">
  6. <img src="../../static/add.png">
  7. </view>
  8. <view class="title" @click="handleAdd">
  9. 添加打卡位置
  10. </view>
  11. <view class="none"></view>
  12. </view>
  13. <!-- 打卡时间列表 -->
  14. <view class="list">
  15. <uni-swipe-action>
  16. <!-- 每一个时间段区域 -->
  17. <uni-swipe-action-item :auto-close="true" :right-options="options" @click="onClick(index)"
  18. v-for="(item,index) in list" :key="index">
  19. <view class="box">
  20. <view class="icon">
  21. <img src="../../static/location2.png">
  22. </view>
  23. <view class="place">
  24. <view class="top">
  25. {{item.name}}
  26. </view>
  27. <view class="center">
  28. 地址:{{item.name}}
  29. </view>
  30. <view class="bottom">
  31. 范围:{{item.radius}}米
  32. </view>
  33. </view>
  34. <view class="right">
  35. <img src="../../static/right.png">
  36. </view>
  37. </view>
  38. </uni-swipe-action-item>
  39. </uni-swipe-action>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. export default {
  45. data() {
  46. return {
  47. // 地点数组
  48. list: [],
  49. // 左滑选项配置
  50. options: [{
  51. text: '删除',
  52. style: {
  53. backgroundColor: '#D43030'
  54. }
  55. }],
  56. }
  57. },
  58. onLoad(options) {
  59. if (options.locations) {
  60. this.list = JSON.parse(options.locations)
  61. uni.setStorageSync("chooseList", this.list)
  62. }
  63. },
  64. onShow() {
  65. uni.removeStorageSync("flag_place")
  66. let arr = uni.getStorageSync("chooseList")
  67. if (arr) {
  68. this.list = arr
  69. }
  70. if (arr.lenght == 0) {
  71. uni.setStorageSync("flag_place", true)
  72. }
  73. },
  74. methods: {
  75. // 点击添加打卡位置回调
  76. handleAdd() {
  77. // 获取用户位置权限
  78. uni.authorize({
  79. scope: 'scope.userLocation',
  80. success: () => {
  81. uni.navigateTo({
  82. url: `/pages/addLocation/addLocation`
  83. })
  84. },
  85. fail() {
  86. uni.showModal({
  87. title: '提示',
  88. content: '请先开启定位权限,否则将无法使用定位功能',
  89. cancelText: '不授权',
  90. confirmText: '授权',
  91. success: function(res) {
  92. if (res.confirm) {
  93. uni.openSetting({
  94. success(res) {}
  95. })
  96. }
  97. }
  98. });
  99. }
  100. })
  101. },
  102. // 点击右侧删除按钮回调
  103. onClick(index) {
  104. uni.showModal({
  105. title: '提示',
  106. content: '确定删除该打卡位置吗?',
  107. success: (res) => {
  108. if (res.confirm) {
  109. uni.showToast({
  110. title: "删除成功",
  111. icon: 'success'
  112. })
  113. this.list.splice(index, 1)
  114. if (this.list.length == 0) {
  115. uni.setStorageSync("flag_place", true)
  116. }
  117. uni.setStorageSync("chooseList", this.list)
  118. }
  119. }
  120. });
  121. },
  122. }
  123. }
  124. </script>
  125. <style lang="scss" scoped>
  126. .container {
  127. padding-top: 20rpx;
  128. .add {
  129. display: flex;
  130. margin: 0 auto;
  131. width: 690rpx;
  132. height: 87rpx;
  133. line-height: 87rpx;
  134. border-radius: 14rpx;
  135. background-color: #fff;
  136. .icon {
  137. flex: 1;
  138. display: flex;
  139. justify-content: center;
  140. align-items: center;
  141. img {
  142. width: 36rpx;
  143. height: 36rpx;
  144. }
  145. }
  146. .title {
  147. flex: 3;
  148. font-size: 30rpx;
  149. color: #0082FC;
  150. }
  151. .none {
  152. flex: 5;
  153. }
  154. }
  155. .list {
  156. margin-top: 20rpx;
  157. padding-bottom: 30rpx;
  158. .box {
  159. display: flex;
  160. align-items: center;
  161. margin: 0 auto;
  162. margin-bottom: 20rpx;
  163. width: 690rpx;
  164. height: 137rpx;
  165. border-radius: 14rpx;
  166. background-color: #fff;
  167. .icon {
  168. margin-top: 10rpx;
  169. width: 75rpx;
  170. text-align: center;
  171. img {
  172. width: 40rpx;
  173. height: 40rpx;
  174. }
  175. }
  176. .place {
  177. width: 540rpx;
  178. .top {
  179. font-size: 32rpx;
  180. overflow: hidden;
  181. white-space: nowrap;
  182. text-overflow: ellipsis;
  183. }
  184. .center {
  185. font-size: 24rpx;
  186. color: #999999;
  187. overflow: hidden;
  188. white-space: nowrap;
  189. text-overflow: ellipsis;
  190. }
  191. .bottom {
  192. font-size: 24rpx;
  193. color: #999999;
  194. overflow: hidden;
  195. white-space: nowrap;
  196. text-overflow: ellipsis;
  197. }
  198. }
  199. .right {
  200. width: 75rpx;
  201. text-align: center;
  202. img {
  203. width: 15rpx;
  204. height: 28rpx;
  205. }
  206. }
  207. }
  208. }
  209. }
  210. // 解决左滑区域突出问题
  211. ::v-deep .uni-swipe_button-group {
  212. margin-bottom: 20rpx;
  213. }
  214. </style>