123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313 |
- <template>
- <view>
- <uni-nav-bar id="nav-bar" status-bar="true" @clickLeft="onBack()" :title="bModifyPassword?'修改密码':'设置密码'"
- color="#000000" fixed="true" :border="false">
- <view slot="left">
- <view class=" flex align-center margin-left">
- <image class="p-left-arrow" src="../../../static/p-left-arrow.png"></image>
- </view>
- </view>
- <view slot="right">
- <view class="make-text-bPurple text-regular margin-right" @click="savePassword">保存</view>
- </view>
- </uni-nav-bar>
- <block v-if="bModifyPassword">
- <view class="card-view password-item flex justify-center ">
- <m-input inputmode="email" style=" margin-left: 46rpx;" type="text" focus clearable v-model="account"
- placeholder="请输入手机号/邮箱">
- </m-input>
- </view>
- <view class="card-view password-item flex justify-center ">
- <m-input inputmode="text" style=" margin-left: 46rpx;" type="password" maxlength="16" displayable v-model="oldPassword"
- placeholder="请输入旧密码">
- </m-input>
- </view>
- <view class="card-view password-item flex justify-center ">
- <m-input inputmode="text" style=" margin-left: 46rpx;" type="password" maxlength="16" displayable v-model="newPassword"
- placeholder="请输入新密码">
- </m-input>
- </view>
- <view class="card-view password-item flex justify-center ">
- <m-input inputmode="text" style=" margin-left: 46rpx;" type="password" maxlength="16" displayable
- v-model="confirmPassword" placeholder="请再次输入新密码">
- </m-input>
- </view>
- </block>
- <block v-else>
- <view class="card-view password-item flex justify-center ">
- <m-input inputmode="email" style=" margin-left: 46rpx;" type="text" focus clearable v-model="account"
- placeholder="请输入手机号/邮箱">
- </m-input>
- </view>
- <view class="card-view cu-form-group ">
- <view style="width: 16rpx;"></view>
- <m-input inputmode="numeric" type="number" focus clearable v-model="verificationCode" placeholder="请输入验证码">
- </m-input>
- <button v-if="bCodeDisabled" class="cu-btn make-bg-bPurple shadow text-white"
- style="background-color: rgb(0,0,0);opacity: 0.5;">
- 重新获取({{count}})</button>
- <button v-else class="cu-btn make-bg-bPurple shadow text-white" @tap="onGetCode">获取验证码</button>
- </view>
- <view class="card-view password-item flex justify-center ">
- <m-input inputmode="text" style=" margin-left: 46rpx;" type="password" maxlength="16" displayable v-model="newPassword"
- placeholder="请输入新密码">
- </m-input>
- </view>
- <view class="card-view password-item flex justify-center ">
- <m-input inputmode="text" style=" margin-left: 46rpx;" type="password" maxlength="16" displayable
- v-model="confirmPassword" placeholder="请确认新密码">
- </m-input>
- </view>
- </block>
- <view class="text-red margin-xl text-regular">密码必须是6-18位字符,数字、字母、特殊字符 (不能是纯数字、字母的组合)</view>
- </view>
- </template>
- <script>
- import service from '../../../util/util-js/service.js';
- import mInput from '../../../components/m-input.vue';
- import verify from '../../../util/util-js/verify.js'
- import config from '@/common/config.js';
- import reqUtil from "@/util/util-js/requstUtil.js";
- import {
- mapState,
- mapMutations
- } from 'vuex'
- export default {
- components: {
- mInput
- },
- data() {
- return {
- account: '',
- oldPassword: '',
- newPassword: '',
- confirmPassword: '',
- verificationCode: '',
- bModifyPassword: true,
- bModifying: false,
- }
- },
- computed: mapState(['bCodeDisabled', 'count']),
- onLoad(option) {
- if (option.bModify) {
- //设置页面状态
- this.bModifyPassword = JSON.parse(option.bModify);
- }
- },
- methods: {
- ...mapMutations(['countDown', 'resetCountDown']),
- onBack() {
- uni.navigateBack({
- delta: 1
- })
- },
- onGetCode() {
- //置灰状态
- if (this.bCodeDisabled) return;
- if (!~this.account.indexOf('@')) {
- if (!verify.checkPhone(this.account)) {
- uni.showToast({
- icon: 'none',
- title: '请输入正确手机号'
- });
- return;
- }
- //调用store 倒计时
- this.countDown({
- account: this.account,
- type: 0
- });
- } else {
- if (!verify.checkEMail(this.account)) {
- uni.showToast({
- icon: 'none',
- title: '请输入正确邮箱号'
- });
- return;
- }
- //调用store 倒计时
- this.countDown({
- account: this.account,
- type: 1
- });
- }
- },
- savePassword() {
- if (this.bModifying) return;
- /**
- * 同时判断两个类型
- */
- if (!~this.account.indexOf('@') && !verify.checkPhone(this.account)) {
- uni.showToast({
- icon: 'none',
- title: '手机号不合法',
- });
- return;
- } else if (~this.account.indexOf('@') && !verify.checkEMail(this.account)) {
- uni.showToast({
- icon: 'none',
- title: '邮箱地址不合法',
- });
- return;
- }
- if (this.bModifyPassword) {
- //如果是修改密码,不需要验证码
- if (!verify.checkPassword(this.oldPassword)) {
- uni.showToast({
- icon: 'none',
- title: '旧的密码格式不合法',
- });
- return;
- }
- if (!verify.checkPassword(this.newPassword)) {
- uni.showToast({
- icon: 'none',
- title: '新的密码格式不合法',
- });
- return;
- }
- } else {
- if (this.verificationCode == '' ||
- this.verificationCode == undefined ||
- this.verificationCode == null) {
- uni.showToast({
- icon: 'none',
- title: '输入验证码',
- });
- return;
- }
- if (!verify.checkPassword(this.newPassword)) {
- uni.showToast({
- icon: 'none',
- title: '新的密码格式不合法',
- });
- return;
- }
- }
- if (!verify.checkPassword(this.confirmPassword)) {
- uni.showToast({
- icon: 'none',
- title: '确认的密码格式不合法',
- });
- return;
- }
- if (this.confirmPassword != this.newPassword) {
- uni.showToast({
- icon: 'none',
- title: '请输入两个相同的密码',
- });
- return;
- }
- this.bModifying = true;
- uni.showToast({
- icon: 'loading',
- title: '',
- duration: 10000
- });
- //todo 处理新密码
- if (this.bModifyPassword) {
- //如果是修改密码,不需要验证码
- reqUtil.requestData(config.URL.MODIFYPASSWORDFROMACCOUNT, {
- "account": this.account,
- "type": !~this.account.indexOf('@') ? 0 : 1,
- "oldPassword": this.oldPassword,
- "newPassword": this.newPassword
- }).then(res => {
- uni.hideToast();
- console.log("MODIFYPASSWORDFROMACCOUNT" + JSON.stringify(res));
- if (res.code == 0) {
- uni.showToast({
- icon: 'success',
- title: '设置密码成功',
- duration: 2000,
- mask: true
- });
- this.$store.state.setPasswordFirstTime = false;
- setTimeout(() => {
- this.onBack();
- }, 2000);
- } else {
- uni.showToast({
- title: '修改密码失败',
- duration: 2000
- });
- }
- this.resetCountDown();
- this.bModifying = false;
- },
- e => {
- console.log(e);
- this.bModifying = false;
- });
- } else {
- reqUtil.requestData(config.URL.MODIFYPASSWORDFROMSMS, {
- "account": this.account,
- "type": !~this.account.indexOf('@') ? 0 : 1,
- "code": this.verificationCode,
- "password": this.newPassword
- }).then(res => {
- console.log("MODIFYPASSWORDFROMSMS" + JSON.stringify(res));
- uni.hideToast();
- if (res.code == 0) {
- uni.showToast({
- icon: 'success',
- title: '修改密码成功',
- duration: 2000,
- mask: true
- });
- this.$store.state.setPasswordFirstTime = false;
- setTimeout(() => {
- this.onBack();
- }, 2000);
- } else {
- uni.showToast({
- title: '修改密码失败',
- duration: 2000
- });
- }
- this.resetCountDown();
- this.bModifying = false;
- },
- e => {
- console.log(e);
- this.bModifying = false;
- });
- }
- }
- }
- }
- </script>
- <style>
- .password-item {
- height: 100rpx;
- }
- .card-view {
- border-radius: 10px;
- }
- </style>
|