teenagePassword.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. <template>
  2. <view>
  3. <PageHeader class="page-heard" :title="'青少年模式'" />
  4. <view class="reserveASeat"></view>
  5. <view class="title-box">
  6. <view class="title" v-if="state == 1">设置家长密码</view>
  7. <view class="title" v-if="state == 2">修改密码</view>
  8. <view class="title" v-if="state == 3">设置新密码</view>
  9. <view class="title" v-if="state == 4">验证密码</view>
  10. <view class="subtitle" v-if="state == 1">此密码为关闭青少年模式的密码</view>
  11. <view class="subtitle" v-if="state == 2">请输入当前密码</view>
  12. <view class="subtitle" v-if="state == 3">请输入当前密码</view>
  13. <view class="subtitle" v-if="state == 4">请输入密码{{ action == 'open' ? '打开' : '关闭' }}青少年模式</view>
  14. </view>
  15. <view class="code-box">
  16. <yi-code ref="code" class="yiCode" :width="590" @onComplete="complete" :focus="false"
  17. :maxlength="4"></yi-code>
  18. </view>
  19. <view class="subtitle" v-if="state == 2 || state == 4"> 忘记了?<span @click="openCustomPopup">联系客服反馈</span> </view>
  20. <view class="subtitle" v-if="state == 3"> 此密码为长期密码,请牢记自己的密码 </view>
  21. <view class="btn-box">
  22. <view class="btn" @click="selection(false)" v-if="state != 4">{{ state != 2 ? '确认' : '下一步' }}</view>
  23. <view class="btn" @click="selection(false)" v-if="state == 4">{{ action == 'open' ? '打开' : '关闭' }}青少年模式
  24. </view>
  25. </view>
  26. <CustomerServicePopup ref="customerServicePopup"></CustomerServicePopup>
  27. </view>
  28. </template>
  29. <script>
  30. import PageHeader from '@/components/PageHeader/PageHeader.vue'
  31. import { getStorage, setStorage, removeStorage } from "@/common/util.js";
  32. import { mapState,mapMutations } from 'vuex';
  33. export default {
  34. components: { PageHeader },
  35. data() {
  36. return {
  37. state: 1,
  38. code: '',
  39. password: '',
  40. originalPassword: '',
  41. newPassword: '',
  42. action: 'open',
  43. }
  44. },
  45. onLoad(e) {
  46. // e.state 1 首次进来设置密码 2修改密码(验证原密码) 3 修改密码(验证新密码) 4 验证原密码后 切换青少年状态
  47. if (e.state) {
  48. this.state = e.state
  49. }
  50. if (e.is_open_young == 1) {
  51. this.action = 'close'
  52. } else if (e.is_open_young == 0 || e.is_open_young == -1) {
  53. this.action = 'open'
  54. }
  55. },
  56. onShow() {
  57. },
  58. onHide() {
  59. },
  60. methods: {
  61. ...mapMutations('rightsManagement',['setTeenageMode']),
  62. openCustomPopup() {
  63. this.$refs.customerServicePopup.$refs.customPopup.open()
  64. },
  65. complete(code) {
  66. this.code = code
  67. this.selection(true)
  68. },
  69. async selection(auto) {
  70. auto = auto || false
  71. if (!this.code || this.code.length != 4) {
  72. uni.showToast({
  73. title: '请输入四位密码',
  74. icon: 'none'
  75. });
  76. return
  77. }
  78. var res
  79. // 设置密码
  80. if (this.state == 1) {
  81. this.password = this.code
  82. if (!auto) {
  83. res = await this.setParentPassword()
  84. }
  85. }
  86. // 验证原密码
  87. if (this.state == 2) {
  88. res = await this.verifyParentPassword()
  89. if (res.str == '密码验证成功') {
  90. this.originalPassword = this.code
  91. this.$refs.code.clear()
  92. res.str = '请输入新密码'
  93. this.state = 3
  94. } else {
  95. res.str = '密码不正确请重新输入'
  96. this.$refs.code.clear() // 清空输入框
  97. }
  98. }
  99. // 设置新的密码
  100. if (this.state == 3) {
  101. if (!auto) {
  102. res = await this.setParentPassword()
  103. }
  104. }
  105. // 验证原密码后切换状态
  106. if (this.state == 4) {
  107. var res1 = await this.verifyParentPassword()
  108. if (res1.str == '密码验证成功') {
  109. res = await this.toggleYoungMode()
  110. this.goBack()
  111. } else {
  112. res1.str = '密码不正确请重新输入'
  113. uni.showToast({
  114. title: res1.str,
  115. icon: 'none'
  116. });
  117. this.$refs.code.clear() // 清空输入框
  118. }
  119. }
  120. if (res && res.str) {
  121. if (res && res.str == '操作成功') {
  122. uni.hideToast();
  123. if (this.action == 'open') {
  124. res.str = '青少年模式已开启'
  125. } else {
  126. res.str = '青少年模式已关闭'
  127. }
  128. }
  129. uni.showToast({
  130. title: res.str,
  131. icon: 'none'
  132. });
  133. }
  134. if (res && res.str == '密码设置成功') {
  135. this.goBack()
  136. }
  137. },
  138. // 设置家长密码
  139. setParentPassword() {
  140. console.log('执行方法');
  141. return new Promise((resolve, reject) => {
  142. var rql = {}
  143. // 第一次设置时
  144. rql.password = this.code
  145. // 修改密码时
  146. if (this.state == 3) {
  147. rql.old_password = this.originalPassword
  148. }
  149. console.log(rql, 111);
  150. uni.request({
  151. url: this.$apiHost + '/Young/setParentPassword',
  152. data: {
  153. uuid: getApp().globalData.uuid,
  154. ...rql
  155. },
  156. header: {
  157. "content-type": "application/json",
  158. 'sign': getApp().globalData.headerSign
  159. },
  160. success: (res) => {
  161. console.log("设置结果:", res.data);
  162. resolve(res.data);
  163. },
  164. fail: (e) => {
  165. console.log("设置失败:", e);
  166. reject(e);
  167. }
  168. });
  169. });
  170. },
  171. // 验证家长密码
  172. verifyParentPassword() {
  173. return new Promise((resolve, reject) => {
  174. uni.request({
  175. url: this.$apiHost + '/Young/verifyParentPassword',
  176. data: {
  177. uuid: getApp().globalData.uuid,
  178. password: this.code
  179. },
  180. header: {
  181. "content-type": "application/json",
  182. 'sign': getApp().globalData.headerSign
  183. },
  184. success: (res) => {
  185. console.log("验证结果:", res.data);
  186. resolve(res.data);
  187. },
  188. fail: (e) => {
  189. console.log("验证失败:", e);
  190. reject(e);
  191. }
  192. });
  193. });
  194. },
  195. // 切换青少年模式状态
  196. toggleYoungMode() {
  197. return new Promise((resolve, reject) => {
  198. uni.request({
  199. url: this.$apiHost + '/Young/toggleYoungMode',
  200. data: {
  201. uuid: getApp().globalData.uuid,
  202. password: this.code,
  203. action: this.action
  204. },
  205. header: {
  206. "content-type": "application/json",
  207. 'sign': getApp().globalData.headerSign
  208. },
  209. success: (res) => {
  210. console.log("切换结果:", res.data);
  211. resolve(res.data);
  212. if (res.data.is_open_young == 1) {
  213. this.setTeenageMode(1);
  214. } else if (res.data.is_open_young == 0) {
  215. this.setTeenageMode(2);
  216. }
  217. },
  218. fail: (e) => {
  219. console.log("切换失败:", e);
  220. reject(e);
  221. }
  222. });
  223. });
  224. },
  225. goBack() {
  226. setTimeout(() => {
  227. uni.navigateBack();
  228. }, 800)
  229. },
  230. }
  231. }
  232. </script>
  233. <style lang="scss">
  234. page {
  235. background-color: #f2f6f2;
  236. font-family: 'PingFang SC-Medium';
  237. min-height: 100vh;
  238. padding-bottom: calc(var(--window-bottom));
  239. box-sizing: border-box;
  240. position: relative;
  241. left: 0;
  242. top: 0;
  243. }
  244. .page-heard {
  245. background-color: #f2f6f2;
  246. }
  247. .reserveASeat {
  248. width: 100%;
  249. height: calc(90rpx + var(--status-bar-height))
  250. }
  251. .title-box {
  252. padding-top: 90rpx;
  253. padding-bottom: 72rpx;
  254. display: flex;
  255. align-items: center;
  256. justify-content: center;
  257. flex-direction: column;
  258. .title {
  259. font-weight: 600;
  260. font-size: 20px;
  261. color: #1F1F1F;
  262. }
  263. .subtitle {
  264. padding: 0;
  265. padding-top: 20rpx;
  266. }
  267. }
  268. .subtitle {
  269. font-size: 24rpx;
  270. color: #999999;
  271. text-align: center;
  272. padding-top: 44rpx;
  273. span {
  274. color: #0084FF;
  275. }
  276. }
  277. .code-box {
  278. padding: 0 80rpx;
  279. .yiCode {
  280. width: 100%;
  281. }
  282. }
  283. .yiCode {
  284. &::v-deep.yi-code {
  285. .yi-code-show {
  286. .yi-code-show-item {
  287. width: 124rpx;
  288. height: 124rpx;
  289. border: 4rpx #000 solid;
  290. border-radius: 20rpx;
  291. font-size: 56rpx;
  292. color: #1F1F1F;
  293. &.yi-code-show-active {
  294. border: solid 2px #ff5500;
  295. animation: myfirst 600ms infinite;
  296. @keyframes myfirst {
  297. 0% {
  298. opacity: 0.1
  299. }
  300. 100% {
  301. opacity: 1
  302. }
  303. }
  304. }
  305. }
  306. }
  307. .yi-code-hide {
  308. height: 124rpx;
  309. }
  310. }
  311. }
  312. .btn-box {
  313. position: absolute;
  314. bottom: 20rpx;
  315. left: 50%;
  316. transform: translateX(-50%);
  317. .btn {
  318. background: #1F1F1F;
  319. color: #fff;
  320. margin: 0 auto;
  321. width: 626rpx;
  322. height: 88rpx;
  323. font-size: 32rpx;
  324. font-family: 'PingFang SC-Bold';
  325. background: #1F1F1F;
  326. border-radius: 58rpx;
  327. display: flex;
  328. align-items: center;
  329. justify-content: center;
  330. }
  331. }
  332. </style>
  333. <style>
  334. .navbar-title
  335. {
  336. font-weight: 500;
  337. font-size: 32px;
  338. font-family: 'PingFang SC-Medium' !important;
  339. }
  340. </style>