teenagePassword.vue 7.7 KB

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