setting.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. <style lang="scss" scoped>
  2. .setting {
  3. font-size: 28rpx;
  4. color: #666;
  5. .s{
  6. .t {
  7. overflow: hidden;
  8. padding: 0 40rpx;
  9. background: #fff;
  10. margin-bottom: 20rpx;
  11. .title {
  12. font-size: 32rpx;
  13. color: #40a7e7;
  14. margin: 26rpx 0;
  15. }
  16. .content{
  17. padding-left: 20rpx;
  18. .subtitle {
  19. font-size: 28rpx;
  20. color: #40a7e7;
  21. }
  22. .item {
  23. display: flex;
  24. justify-content: space-between;
  25. align-items: center;
  26. height: 100rpx;
  27. .tip {
  28. font-size: 22rpx;
  29. color: #999;
  30. display: flex;
  31. justify-content: flex-start;
  32. align-items: center;
  33. &image {
  34. width: 24rpx;
  35. height: 24rpx;
  36. margin-right: 10rpx;
  37. }
  38. }
  39. }
  40. }
  41. }
  42. }
  43. .toast{
  44. .mask {
  45. position: fixed;
  46. z-index: 9;
  47. top: 0;
  48. right: 0;
  49. bottom: 0;
  50. left: 0;
  51. margin: auto;
  52. background: rgba(0, 0, 0, .5);
  53. }
  54. .wrapper {
  55. position: fixed;
  56. z-index: 10;
  57. top: 0;
  58. right: 0;
  59. bottom: 0;
  60. left: 0;
  61. margin: auto;
  62. background: #fff;
  63. font-size: 24rpx;
  64. color: #333;
  65. width: 60%;
  66. height: 400rpx;
  67. border-radius: 14rpx;
  68. .box {
  69. height: 400rpx;
  70. padding: 20rpx 28rpx;
  71. overflow: scroll;
  72. .t {
  73. font-size: 28rpx;
  74. color: #40a7e7;
  75. margin: 20rpx 0;
  76. padding: 0;
  77. }
  78. .content {
  79. line-height: 1.8em;
  80. text-align: justify;
  81. &text {
  82. display: block;
  83. margin-bottom: 10rpx;
  84. }
  85. }
  86. }
  87. }
  88. }
  89. }
  90. .item .tip image {
  91. width: 24rpx;
  92. height: 24rpx;
  93. margin-right: 10rpx;
  94. }
  95. .more {
  96. width: 32rpx;
  97. height: 32rpx;
  98. }
  99. </style>
  100. <template>
  101. <view class='setting'>
  102. <!-- 自定义 -->
  103. <view class='s'>
  104. <!-- 检查更新 -->
  105. <!-- #ifdef MP-WEIXIN -->
  106. <view class='t'>
  107. <view class='title'>
  108. <view>检查更新</view>
  109. </view>
  110. <view class='content'>
  111. <view class='item'>
  112. <view>
  113. <view>更新提醒</view>
  114. <view class='tip' @tap="updateInstruc">
  115. <image src='/static/question.png'></image>
  116. <text v-if='enableUpdate'>在首页检测到新版本,会提示更新</text>
  117. <text v-if='!enableUpdate'>基础库版本需高于 1.9.90,当前基础库版本为 {{SDKVersion}}</text>
  118. </view>
  119. </view>
  120. <switch color='#40a7e7' :checked='setting.forceUpdate' @change='switchChange' data-switchParam='forceUpdate'></switch>
  121. </view>
  122. </view>
  123. </view>
  124. <!-- #endif -->
  125. <!-- 小工具 -->
  126. <view class='t'>
  127. <view class='title'>小工具</view>
  128. <view class='content'>
  129. <view class='subtitle'>NFC</view>
  130. <view class='item' @tap='getHCEState'>
  131. <view>检测是否支持NFC</view>
  132. <image class='more' src='/static/arrow.png'></image>
  133. </view>
  134. </view>
  135. <!-- #ifndef H5 -->
  136. <view class='content'>
  137. <view class='subtitle'>屏幕亮度</view>
  138. <view class='item'>
  139. <view>
  140. <view>当前屏幕亮度</view>
  141. <view class='tip'>范围0~100,0 最暗,100 最亮</view>
  142. </view>
  143. <view>{{screenBrightness}}</view>
  144. </view>
  145. <view class='item' @tap='setScreenBrightness'>
  146. <view :style="{width:100+'%'}">
  147. <view>设置屏幕亮度</view>
  148. <slider :value='screenBrightness' min='0' max='100' step='1' block-size='12' block-color='#40a7e7' activeColor='#40a7e7' show-value='true' @change='screenBrightnessChanging' @changing='screenBrightnessChanging'></slider>
  149. </view>
  150. </view>
  151. <view class='item'>
  152. <view>
  153. <view>保持常亮</view>
  154. <view class='tip'>仅在当前小程序、当次生效,离开小程序后设置失效</view>
  155. </view>
  156. <switch color='#40a7e7' @change='switchChange' data-switchparam='keepscreenon' :checked='setting.keepscreenon'></switch>
  157. </view>
  158. </view>
  159. <!-- #endif -->
  160. <view class='content'>
  161. <view class='subtitle'>系统信息</view>
  162. <view class='item' @tap='getsysteminfo'>
  163. <view>查看系统信息</view>
  164. <image class='more' src='/static/arrow.png'></image>
  165. </view>
  166. </view>
  167. <view class='content'>
  168. <view class='subtitle'>是否开启手势解锁</view>
  169. <view class='item'>
  170. <view>开启后,每次都需解锁进入</view>
  171. <switch color='#40a7e7' :checked='setting.gesture' @change='switchChange' data-switchParam='gesture'></switch>
  172. </view>
  173. </view>
  174. </view>
  175. <!-- 清除数据 -->
  176. <view class='t'>
  177. <view class='title'>清除数据</view>
  178. <view class='content'>
  179. <view class='item' @tap='removeStorage' data-type='setting'>
  180. <view>
  181. <view>恢复初始化设置</view>
  182. <view class='tip'>
  183. <image src='/static/danger.png'></image>
  184. <text>所有设置信息都将被清除</text>
  185. </view>
  186. </view>
  187. <image class='more' src='/static/arrow.png'></image>
  188. </view>
  189. <view class='item' @tap='removeStorage' data-type='all'>
  190. <view>
  191. <view>清除所有本地数据</view>
  192. <view class='tip'>
  193. <image src='/static/danger.png'></image>
  194. <text>所有本地数据都将被清除</text>
  195. </view>
  196. </view>
  197. <image class='more' src='/static/arrow.png'></image>
  198. </view>
  199. </view>
  200. </view>
  201. <view class='t'>
  202. <view class='title'>抽奖</view>
  203. <view class='content'>
  204. <view class='item' @tap='LuckDraw'>
  205. <view>
  206. <view>抽奖设置</view>
  207. </view>
  208. <image class='more' src='/static/arrow.png'></image>
  209. </view>
  210. </view>
  211. </view>
  212. </view>
  213. <!-- toast -->
  214. <view class='toast' v-if='show'>
  215. <view class='mask' @tap='hide'></view>
  216. <view class='wrapper'>
  217. <view class='box'>
  218. <view class='t'>兼容性</view>
  219. <view class='content'>由于小程序基础库从 1.9.90 开始支持 wx.getUpdateManager API,故基础库低于该版本的会忽略该设置。</view>
  220. <view class='t'>启动机制</view>
  221. <view class='content'>小程序启动会有两种情况,一种是「冷启动」,一种是「热启动」。 假如用户已经打开过某小程序,然后在一定时间内再次打开该小程序,此时无需重新启动,只需将后台的小程序切换到前台,这个过程就是热启动;冷启动指的是用户首次打开或小程序被微信主动销毁后再次打开的情况,此时小程序需要重新加载启动。</view>
  222. <view class='t'>更新机制</view>
  223. <view class='content'>小程序冷启动时如果发现有新版本,将会异步下载新版本的代码包,并同时用客户端本地的包进行启动,即新版本的小程序需要等下一次冷启动才会应用上。</view>
  224. <view class='t'>运行机制</view>
  225. <view class='content'>
  226. <text>1、小程序没有重启的概念;</text>
  227. <text>2、当小程序进入后台,客户端会维持一段时间的运行状态,超过一定时间后(目前是5分钟)会被微信主动销毁;</text>
  228. <text>3、当短时间内(5s)连续收到两次以上系统内存告警,会进行小程序的销毁。</text>
  229. </view>
  230. </view>
  231. </view>
  232. </view>
  233. </view>
  234. </template>
  235. <script>
  236. import {
  237. mapState,
  238. mapMutations
  239. } from "vuex"
  240. export default {
  241. data() {
  242. return {
  243. show: false,
  244. screenBrightness: '获取中',
  245. keepscreenon: false,
  246. SDKVersion: '',
  247. enableUpdate: true
  248. }
  249. },
  250. computed: {
  251. ...mapState({
  252. setting: state => state.global.setting
  253. })
  254. },
  255. watch:{
  256. setting: {
  257. handler: function(old, newold){
  258. console.log(old, newold,"监听")
  259. },
  260. deep: true
  261. }
  262. },
  263. onLoad() {
  264. //#ifndef H5
  265. this.getScreenBrightness()
  266. //#endif
  267. },
  268. onShow() {
  269. console.log(this.setting,"---------")
  270. },
  271. mounted() {
  272. },
  273. methods:{
  274. ...mapMutations(["setTing"]),
  275. updateInstruc() {
  276. this.show = true
  277. },
  278. getsysteminfo() {
  279. uni.navigateTo({
  280. url:"/pages/syeminfo/syeminfo"
  281. })
  282. },
  283. LuckDraw() {
  284. uni.navigateTo({
  285. url:"/pages/luckdraw/luckdraw"
  286. })
  287. },
  288. switchChange(e) {
  289. console.log(e)
  290. let dataset = e.currentTarget.dataset
  291. let switchparam = dataset.switchparam
  292. let setting = this.setting
  293. if (switchparam === 'forceUpdate') {
  294. if (this.enableUpdate) {
  295. setting[switchparam] = (e.detail || {}).value
  296. } else {
  297. setting[switchparam] = false
  298. uni.showToast({
  299. title: '基础库版本较低,无法使用该功能',
  300. icon: 'none',
  301. duration: 2000,
  302. })
  303. }
  304. } else if (switchparam === 'keepscreenon') {
  305. setting[switchparam] = (e.detail || {}).value
  306. // #ifndef H5
  307. this.setKeepScreenOn()
  308. // #endif
  309. } else {
  310. setting[switchparam] = (e.detail || {}).value
  311. if(e.detail.value) {
  312. setTimeout(function() {
  313. uni.navigateTo({
  314. url:"/pages/gesture/gesture"
  315. })
  316. }, 100);
  317. }
  318. }
  319. this.setTing(setting)
  320. },
  321. screenBrightnessChanging(e) {
  322. console.log(e.detail.value)
  323. //#ifndef H5
  324. this.setScreenBrightness(e.detail.value)
  325. this.screenBrightness = e.detail.value
  326. //#endif
  327. },
  328. setScreenBrightness (val) {
  329. uni.setScreenBrightness({
  330. value: val / 100,
  331. success: function () {
  332. console.log('success')
  333. }
  334. })
  335. },
  336. getScreenBrightness() {
  337. uni.getScreenBrightness({
  338. success: (res) => {
  339. this.screenBrightness = Number(res.value * 100).toFixed(0)
  340. },
  341. fail: (res) => {
  342. this.screenBrightness = '获取失败'
  343. }
  344. })
  345. },
  346. getHCEState () {
  347. //#ifdef MP-WEIXIN || APP-PLUS
  348. uni.showLoading({title: '检测中...'})
  349. uni.getHCEState({
  350. success: function (res) {
  351. uni.hideLoading()
  352. uni.showModal({
  353. title: '检测结果',
  354. content: '该设备支持NFC功能',
  355. showCancel: false,
  356. confirmText: '朕知道了',
  357. confirmColor: '#40a7e7',
  358. })
  359. },
  360. fail: function (res) {
  361. wx.hideLoading()
  362. wx.showModal({
  363. title: '检测结果',
  364. content: '该设备不支持NFC功能',
  365. showCancel: false,
  366. confirmText: '朕知道了',
  367. confirmColor: '#40a7e7',
  368. })
  369. }
  370. })
  371. //#endif
  372. //#ifndef APP-PLUS || MP-WEIXIN
  373. uni.showToast({
  374. title:"仅支持App及小程序",
  375. icon:"none"
  376. })
  377. //#endif
  378. },
  379. removeStorage(e) {
  380. let type = e.currentTarget.dataset.type
  381. this.clear(type)
  382. },
  383. clear(type) {
  384. switch (type){
  385. case "setting":
  386. this.setClear()
  387. break;
  388. case "all":
  389. this.locclear()
  390. break;
  391. }
  392. },
  393. setClear() {
  394. let that = this
  395. uni.showModal({
  396. title: '提示',
  397. content: '确认要初始化设置',
  398. cancelText: '容朕想想',
  399. confirmColor: '#40a7e7',
  400. success: (res) => {
  401. if (res.confirm) {
  402. uni.removeStorageSync("word")
  403. Object.keys(that.setting).forEach(function(key){
  404. that.setting[key] = false
  405. that.$set(that.setting, key, false)
  406. console.log(that.setting);
  407. });
  408. uni.showToast({
  409. title: '初始化成功', icon:"none"
  410. })
  411. this.setTing(that.setting)
  412. }
  413. }
  414. })
  415. },
  416. locclear() {
  417. uni.showModal({
  418. title: '提示',
  419. content: '确认要删除',
  420. cancelText: '容朕想想',
  421. confirmColor: '#40a7e7',
  422. success: (res) => {
  423. if (res.confirm) {
  424. uni.clearStorage({
  425. success: (res) => {
  426. uni.showToast({
  427. title: '数据已清除', icon:"none"
  428. })
  429. }
  430. })
  431. //返回首页
  432. }
  433. }
  434. })
  435. },
  436. hide() {
  437. this.show = false
  438. },
  439. ifDisableUpdate () {
  440. let systeminfo = getApp().globalData.systeminfo
  441. let SDKVersion = systeminfo.SDKVersion
  442. let version = cmpVersion(SDKVersion, '1.9.90')
  443. if (version >=0) {
  444. this.setData({
  445. SDKVersion,
  446. enableUpdate: true,
  447. })
  448. } else {
  449. this.setData({
  450. SDKVersion,
  451. enableUpdate: false,
  452. })
  453. }
  454. },
  455. setKeepScreenOn() {
  456. uni.setKeepScreenOn({
  457. keepScreenOn: true
  458. })
  459. }
  460. }
  461. }
  462. </script>