teenagePassword.vue 8.0 KB

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