From c22a9242216e522d21be1a743dc3020115e1bd48 Mon Sep 17 00:00:00 2001 From: lwh <2679599887@qq.com> Date: Fri, 9 Jun 2023 18:32:04 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=AE=E6=94=B9=E4=B8=BB=E9=A2=98?= =?UTF-8?q?=E8=89=B2=EF=BC=8C=E5=AE=8C=E5=96=84=E6=94=B6=E8=B4=A7=E5=9C=B0?= =?UTF-8?q?=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.wxss | 1 - config/index.js | 2 +- pages/login/login.js | 18 +- pages/usercenter/address/edit/index.js | 198 ++++++++++++------ pages/usercenter/address/edit/index.wxml | 4 +- pages/usercenter/address/edit/util.js | 33 --- pages/usercenter/address/list/index.js | 88 ++------ pages/usercenter/address/list/index.wxml | 4 +- pages/usercenter/address/list/index.wxss | 2 +- pages/usercenter/address/list/util.js | 10 +- .../components/ui-address-item/index.wxml | 4 +- pages/usercenter/person-info/index.js | 110 ++++++++-- pages/usercenter/person-info/index.json | 5 +- pages/usercenter/person-info/index.wxml | 15 +- pages/usercenter/person-info/index.wxss | 15 +- services/_utils/request.js | 2 +- services/address/addOrUpdateAddress.js | 22 ++ services/address/fetchAddress.js | 72 +++---- services/address/getRegionTreeList.js | 23 ++ services/login/login.js | 41 ++-- services/login/phone-register.js | 18 +- services/usercenter/fetchPerson.js | 54 ++--- services/usercenter/set/logout.js | 11 +- services/usercenter/updatePerson.js | 22 ++ style/theme.wxss | 18 +- 25 files changed, 465 insertions(+), 327 deletions(-) delete mode 100644 pages/usercenter/address/edit/util.js create mode 100644 services/address/addOrUpdateAddress.js create mode 100644 services/address/getRegionTreeList.js create mode 100644 services/usercenter/updatePerson.js diff --git a/app.wxss b/app.wxss index 9ff2554..7a18c15 100644 --- a/app.wxss +++ b/app.wxss @@ -1,3 +1,2 @@ @import 'style/iconfont.wxss'; - @import 'style/theme.wxss'; \ No newline at end of file diff --git a/config/index.js b/config/index.js index 3d59a2c..afc38cc 100644 --- a/config/index.js +++ b/config/index.js @@ -4038,7 +4038,7 @@ export const areaData = [ children: [ { label: '上海市', - value: '310100', + value: '310010', children: [ { label: '黄浦区', diff --git a/pages/login/login.js b/pages/login/login.js index 092a499..c645a41 100644 --- a/pages/login/login.js +++ b/pages/login/login.js @@ -8,6 +8,7 @@ Page({ * 页面的初始数据 */ data: { + back: true, bg_image: "", checked: true, code: "" @@ -24,7 +25,13 @@ Page({ } // 登录请求 - login(data) + login(data).then((res) => { + if (res.data != null) { + that.setData({ + back: false + }) + } + }) } else {} }, @@ -76,9 +83,12 @@ Page({ * 生命周期函数--监听页面卸载 */ onUnload() { - wx.navigateTo({ - url: `/pages/home/home` - }); + let that = this + if (that.data.back == true) { + wx.reLaunch({ + url: '/pages/home/home' + }) + } }, /** diff --git a/pages/usercenter/address/edit/index.js b/pages/usercenter/address/edit/index.js index 33b2f19..67b5993 100644 --- a/pages/usercenter/address/edit/index.js +++ b/pages/usercenter/address/edit/index.js @@ -1,13 +1,25 @@ import Toast from 'tdesign-miniprogram/toast/index'; -import { fetchDeliveryAddress } from '../../../../services/address/fetchAddress'; -import { areaData } from '../../../../config/index'; -import { resolveAddress, rejectAddress } from './util'; +import { + fetchDeliveryAddress +} from '~/services/address/fetchAddress'; +import { + addOrUpdateAddress +} from '~/services/address/addOrUpdateAddress'; +import { + areaData +} from '~/config/index'; + const innerPhoneReg = '^1(?:3\\d|4[4-9]|5[0-35-9]|6[67]|7[0-8]|8\\d|9\\d)\\d{8}$'; const innerNameReg = '^[a-zA-Z\\d\\u4e00-\\u9fa5]+$'; -const labelsOptions = [ - { id: 0, name: '家' }, - { id: 1, name: '公司' }, +const labelsOptions = [{ + id: 0, + name: '家' + }, + { + id: 1, + name: '公司' + }, ]; Page({ @@ -47,15 +59,17 @@ Page({ privateData: { verifyTips: '', }, + + onLoad(options) { - const { id } = options; + const { + id + } = options; this.init(id); }, onUnload() { - if (!this.hasSava) { - rejectAddress(); - } + }, hasSava: false, @@ -65,10 +79,17 @@ Page({ this.getAddressDetail(Number(id)); } }, + + /** 获取收货地址详情 */ getAddressDetail(id) { fetchDeliveryAddress(id).then((detail) => { - this.setData({ locationState: detail }, () => { - const { isLegal, tips } = this.onVerifyInputLegal(); + this.setData({ + locationState: detail + }, () => { + const { + isLegal, + tips + } = this.onVerifyInputLegal(); this.setData({ submitActive: isLegal, }); @@ -76,12 +97,17 @@ Page({ }); }); }, + + /** 地区Change事件 */ onInputValue(e) { - const { item } = e.currentTarget.dataset; + const { + item + } = e.currentTarget.dataset; if (item === 'address') { - const { selectedOptions = [] } = e.detail; - this.setData( - { + const { + selectedOptions = [] + } = e.detail; + this.setData({ 'locationState.provinceCode': selectedOptions[0].value, 'locationState.provinceName': selectedOptions[0].label, 'locationState.cityName': selectedOptions[1].label, @@ -91,7 +117,10 @@ Page({ areaPickerVisible: false, }, () => { - const { isLegal, tips } = this.onVerifyInputLegal(); + const { + isLegal, + tips + } = this.onVerifyInputLegal(); this.setData({ submitActive: isLegal, }); @@ -99,13 +128,17 @@ Page({ }, ); } else { - const { value = '' } = e.detail; - this.setData( - { + const { + value = '' + } = e.detail; + this.setData({ [`locationState.${item}`]: value, }, () => { - const { isLegal, tips } = this.onVerifyInputLegal(); + const { + isLegal, + tips + } = this.onVerifyInputLegal(); this.setData({ submitActive: isLegal, }); @@ -115,12 +148,18 @@ Page({ } }, onPickArea() { - this.setData({ areaPickerVisible: true }); + this.setData({ + areaPickerVisible: true + }); }, onPickLabels(e) { - const { item } = e.currentTarget.dataset; const { - locationState: { labelIndex = undefined }, + item + } = e.currentTarget.dataset; + const { + locationState: { + labelIndex = undefined + }, labels = [], } = this.data; let payload = { @@ -128,7 +167,10 @@ Page({ addressTag: labels[item].name, }; if (item === labelIndex) { - payload = { labelIndex: null, addressTag: '' }; + payload = { + labelIndex: null, + addressTag: '' + }; } this.setData({ 'locationState.labelIndex': payload.labelIndex, @@ -141,10 +183,16 @@ Page({ }); }, confirmHandle() { - const { labels, labelValue } = this.data; + const { + labels, + labelValue + } = this.data; this.setData({ visible: false, - labels: [...labels, { id: labels[labels.length - 1].id + 1, name: labelValue }], + labels: [...labels, { + id: labels[labels.length - 1].id + 1, + name: labelValue + }], labelValue: '', }); }, @@ -154,15 +202,25 @@ Page({ labelValue: '', }); }, - onCheckDefaultAddress({ detail }) { - const { value } = detail; + onCheckDefaultAddress({ + detail + }) { + const { + value + } = detail; this.setData({ 'locationState.isDefault': value, }); }, + /** 表单验证 */ onVerifyInputLegal() { - const { name, phone, detailAddress, districtName } = this.data.locationState; + const { + name, + phone, + detailAddress, + districtName + } = this.data.locationState; const prefixPhoneReg = String(this.properties.phoneReg || innerPhoneReg); const prefixNameReg = String(this.properties.nameReg || innerNameReg); const nameRegExp = new RegExp(prefixNameReg); @@ -216,7 +274,10 @@ Page({ }; }, - builtInSearch({ code, name }) { + builtInSearch({ + code, + name + }) { return new Promise((resolve, reject) => { wx.getSetting({ success: (res) => { @@ -259,7 +320,10 @@ Page({ }, onSearchAddress() { - this.builtInSearch({ code: 'scope.userLocation', name: '地址位置' }).then(() => { + this.builtInSearch({ + code: 'scope.userLocation', + name: '地址位置' + }).then(() => { wx.chooseLocation({ success: (res) => { if (res.name) { @@ -294,8 +358,12 @@ Page({ }); }); }, + + /** 保存 */ formSubmit() { - const { submitActive } = this.data; + const { + submitActive + } = this.data; if (!submitActive) { Toast({ context: this, @@ -306,46 +374,50 @@ Page({ }); return; } - const { locationState } = this.data; + const { + locationState + } = this.data; this.hasSava = true; - resolveAddress({ - saasId: '88888888', - uid: `88888888205500`, - authToken: null, - id: locationState.addressId, - addressId: locationState.addressId, - phone: locationState.phone, - name: locationState.name, - countryName: locationState.countryName, - countryCode: locationState.countryCode, - provinceName: locationState.provinceName, - provinceCode: locationState.provinceCode, - cityName: locationState.cityName, - cityCode: locationState.cityCode, - districtName: locationState.districtName, - districtCode: locationState.districtCode, - detailAddress: locationState.detailAddress, - isDefault: locationState.isDefault === 1 ? 1 : 0, - addressTag: locationState.addressTag, - latitude: locationState.latitude, - longitude: locationState.longitude, - storeId: null, + addOrUpdateAddress({ + CustomerAddressId: locationState.customerAddressId, + CustomerAddressGuid: locationState.customerAddressGuid, + // countryName: locationState.countryName, // 国家 + // countryCode: locationState.countryCode, + ProvinceCode: locationState.provinceCode, // 省Code + CityCode: locationState.cityCode, // 市Code + DistrictCode: locationState.districtCode, // 区Code + CustomerAddressPhone: locationState.phone, // 手机号 + CustomerAddressName: locationState.name, // 收货人 + CustomerAddressDetailed: locationState.detailAddress, // 地址 + IsDefault: locationState.isDefault === true ? 1 : 0, // 是否为默认地址 + }).then((res) => { + wx.reLaunch({ + url: '/pages/usercenter/address/list/index', + }) }); - wx.navigateBack({ delta: 1 }); }, + + /** 获取微信地址 */ getWeixinAddress(e) { - const { locationState } = this.data; + const { + locationState + } = this.data; const weixinAddress = e.detail; - this.setData( - { - locationState: { ...locationState, ...weixinAddress }, + this.setData({ + locationState: { + ...locationState, + ...weixinAddress + }, }, () => { - const { isLegal, tips } = this.onVerifyInputLegal(); + const { + isLegal, + tips + } = this.onVerifyInputLegal(); this.setData({ submitActive: isLegal, }); @@ -353,4 +425,4 @@ Page({ }, ); }, -}); +}); \ No newline at end of file diff --git a/pages/usercenter/address/edit/index.wxml b/pages/usercenter/address/edit/index.wxml index e8d46a9..8fede12 100644 --- a/pages/usercenter/address/edit/index.wxml +++ b/pages/usercenter/address/edit/index.wxml @@ -69,7 +69,7 @@ - - + --> { - let resolver; - let rejecter; - const nextPromise = new Promise((resolve, reject) => { - resolver = resolve; - rejecter = reject; - }); - - addressPromise.push({ resolver, rejecter }); - - return nextPromise; -}; - -/** 用户保存了一个地址 */ -export const resolveAddress = (address) => { - const allAddress = [...addressPromise]; - addressPromise = []; - - console.info('用户保存了一个地址', address); - - allAddress.forEach(({ resolver }) => resolver(address)); -}; - -/** 取消编辑 */ -export const rejectAddress = () => { - const allAddress = [...addressPromise]; - addressPromise = []; - - allAddress.forEach(({ rejecter }) => rejecter(new Error('cancel'))); -}; diff --git a/pages/usercenter/address/list/index.js b/pages/usercenter/address/list/index.js index 7e24d37..701d6ac 100644 --- a/pages/usercenter/address/list/index.js +++ b/pages/usercenter/address/list/index.js @@ -1,14 +1,13 @@ /* eslint-disable no-param-reassign */ -import { fetchDeliveryAddressList } from '../../../../services/address/fetchAddress'; +import { fetchDeliveryAddressList } from '~/services/address/fetchAddress'; import Toast from 'tdesign-miniprogram/toast/index'; import { resolveAddress, rejectAddress } from './util'; -import { getAddressPromise } from '../edit/util'; Page({ data: { addressList: [], deleteID: '', - showDeleteConfirm: false, + showDeleteConfirm: true, isOrderSure: false, }, @@ -26,26 +25,29 @@ Page({ this.selectMode = !!selectMode; this.init(); }, - init() { this.getAddressList(); }, onUnload() { if (this.selectMode && !this.hasSelect) { - rejectAddress(); + rejectAddress(this.data.addressList); } }, + + /** 获取收货地址列表 */ getAddressList() { const { id } = this.data; fetchDeliveryAddressList().then((addressList) => { addressList.forEach((address) => { - if (address.id === id) { + if (address.customerAddressGuid === id) { address.checked = true; } }); this.setData({ addressList }); }); }, + + /** 获取微信地址 */ getWXAddressHandle() { wx.chooseAddress({ success: (res) => { @@ -80,6 +82,8 @@ Page({ }, }); }, + + /** 删除地址操作 */ confirmDeleteHandle({ detail }) { const { id } = detail || {}; if (id !== undefined) { @@ -109,83 +113,25 @@ Page({ showDeleteConfirm: false, }); }, - editAddressHandle({ detail }) { - this.waitForNewAddress(); - const { id } = detail || {}; - wx.navigateTo({ url: `/pages/usercenter/address/edit/index?id=${id}` }); + /** 跳转编辑 */ + editAddressHandle({ detail }) { + const { customerAddressId } = detail || {}; + wx.navigateTo({ url: `/pages/usercenter/address/edit/index?id=${customerAddressId}` }); }, selectHandle({ detail }) { if (this.selectMode) { this.hasSelect = true; - resolveAddress(detail); + resolveAddress(this.data.addressList,detail); wx.navigateBack({ delta: 1 }); } else { this.editAddressHandle({ detail }); } }, + + /** 跳转添加 */ createHandle() { - this.waitForNewAddress(); wx.navigateTo({ url: '/pages/usercenter/address/edit/index' }); }, - waitForNewAddress() { - getAddressPromise() - .then((newAddress) => { - let addressList = [...this.data.addressList]; - - newAddress.phoneNumber = newAddress.phone; - newAddress.address = `${newAddress.provinceName}${newAddress.cityName}${newAddress.districtName}${newAddress.detailAddress}`; - newAddress.tag = newAddress.addressTag; - - if (!newAddress.addressId) { - newAddress.id = `${addressList.length}`; - newAddress.addressId = `${addressList.length}`; - - if (newAddress.isDefault === 1) { - addressList = addressList.map((address) => { - address.isDefault = 0; - - return address; - }); - } else { - newAddress.isDefault = 0; - } - - addressList.push(newAddress); - } else { - addressList = addressList.map((address) => { - if (address.addressId === newAddress.addressId) { - return newAddress; - } - return address; - }); - } - - addressList.sort((prevAddress, nextAddress) => { - if (prevAddress.isDefault && !nextAddress.isDefault) { - return -1; - } - if (!prevAddress.isDefault && nextAddress.isDefault) { - return 1; - } - return 0; - }); - - this.setData({ - addressList: addressList, - }); - }) - .catch((e) => { - if (e.message !== 'cancel') { - Toast({ - context: this, - selector: '#t-toast', - message: '地址编辑发生错误', - icon: '', - duration: 1000, - }); - } - }); - }, }); diff --git a/pages/usercenter/address/list/index.wxml b/pages/usercenter/address/list/index.wxml index c9d85d3..d393db5 100644 --- a/pages/usercenter/address/list/index.wxml +++ b/pages/usercenter/address/list/index.wxml @@ -11,7 +11,7 @@ extra-space="{{extraSpace}}" class-prefix="ym" address="{{address}}" - data-id="{{address.id}}" + data-id="{{address.customerAddressGuid}}" bind:onSelect="selectHandle" bind:onDelete="deleteAddressHandle" bind:onEdit="editAddressHandle" @@ -33,7 +33,7 @@ isCustomStyle="{{true}}" bind:navigate="waitForNewAddress" /> - + { }; /** 用户选择了一个地址 */ -export const resolveAddress = (address) => { - const allAddress = [...addressPromise]; - addressPromise = []; - +export const resolveAddress = (allAddress,address) => { allAddress.forEach(({ resolver }) => resolver(address)); }; /** 用户没有选择任何地址只是返回上一页了 */ -export const rejectAddress = () => { - const allAddress = [...addressPromise]; - addressPromise = []; - +export const rejectAddress = (allAddress) => { allAddress.forEach(({ rejecter }) => rejecter(new Error('cancel'))); }; diff --git a/pages/usercenter/components/ui-address-item/index.wxml b/pages/usercenter/components/ui-address-item/index.wxml index 26c44fd..ccf3263 100644 --- a/pages/usercenter/components/ui-address-item/index.wxml +++ b/pages/usercenter/components/ui-address-item/index.wxml @@ -15,8 +15,8 @@ - 默认 - {{address.tag}} + 默认 + {{address.address}} diff --git a/pages/usercenter/person-info/index.js b/pages/usercenter/person-info/index.js index fb5db98..ff210bb 100644 --- a/pages/usercenter/person-info/index.js +++ b/pages/usercenter/person-info/index.js @@ -1,5 +1,12 @@ -import { fetchPerson } from '../../../services/usercenter/fetchPerson'; -import { phoneEncryption } from '../../../utils/util'; +import { + fetchPerson +} from '~/services/usercenter/fetchPerson'; +import { + updatePerson +} from '~/services/usercenter/updatePerson'; +import { + phoneEncryption +} from '~/utils/util'; import Toast from 'tdesign-miniprogram/toast/index'; Page({ @@ -11,8 +18,7 @@ Page({ phoneNumber: '', }, showUnbindConfirm: false, - pickerOptions: [ - { + pickerOptions: [{ name: '男', code: '1', }, @@ -30,17 +36,51 @@ Page({ init() { this.fetchData(); }, + fetchData() { - fetchPerson().then((personInfo) => { + fetchPerson().then(({ + personInfo + }) => { this.setData({ personInfo, 'personInfo.phoneNumber': phoneEncryption(personInfo.phoneNumber), }); }); }, - onClickCell({ currentTarget }) { - const { dataset } = currentTarget; - const { nickName } = this.data.personInfo; + + /** 提交 */ + submit() { + let personInfo = this.data.personInfo + let data = { + customerAvatar: personInfo.avatarUrl, + customerNickname: personInfo.nickName, + customerGender: personInfo.gender, + } + updatePerson(data).then((res) => { + if (res.code == 200) { + Toast({ + context: this, + selector: '#t-toast', + message: `保存成功`, + theme: 'success', + }) + wx.reLaunch({ + url: `/pages/usercenter/index`, + }); + } + }) + }, + + /** 点击单元格 */ + onClickCell({ + currentTarget + }) { + const { + dataset + } = currentTarget; + const { + nickName + } = this.data.personInfo; switch (dataset.type) { case 'gender': @@ -67,9 +107,10 @@ Page({ }); }, onConfirm(e) { - const { value } = e.detail; - this.setData( - { + const { + value + } = e.detail; + this.setData({ typeVisible: false, 'personInfo.gender': value, }, @@ -83,7 +124,17 @@ Page({ }, ); }, + + /** 修改昵称 */ + changeNickName(e) { + this.setData({ + 'personInfo.nickName': e.detail.value + }) + }, + + /** 修改头像 */ async toModifyAvatar() { + let that = this try { const tempFilePath = await new Promise((resolve, reject) => { wx.chooseImage({ @@ -91,24 +142,47 @@ Page({ sizeType: ['compressed'], sourceType: ['album', 'camera'], success: (res) => { - const { path, size } = res.tempFiles[0]; + const { + path, + size + } = res.tempFiles[0]; + const tempFilePaths = res.tempFilePaths; + let tempFilePath = tempFilePaths[0]; + // 上传图片到服务器 + wx.uploadFile({ + url: 'http://localhost:8888/api/Common/UploadFile', // 上传接口地址 + filePath: tempFilePath, // 要上传的文件的临时路径 + name: 'file', // 上传文件对应的字段名 + success: function (uploadRes) { + // 上传成功,服务器返回的数据 + let url = JSON.parse(uploadRes.data).data.url + that.setData({ + 'personInfo.avatarUrl': url + }) + + }, + fail: function (uploadError) { + // 上传失败,处理错误 + console.error(uploadError); + } + }); if (size <= 10485760) { resolve(path); } else { - reject({ errMsg: '图片大小超出限制,请重新上传' }); + reject({ + errMsg: '图片大小超出限制,请重新上传' + }); } }, fail: (err) => reject(err), }); }); - const tempUrlArr = tempFilePath.split('/'); - const tempFileName = tempUrlArr[tempUrlArr.length - 1]; Toast({ context: this, selector: '#t-toast', - message: `已选择图片-${tempFileName}`, + message: `头像上传成功`, theme: 'success', - }); + }) } catch (error) { if (error.errMsg === 'chooseImage:fail cancel') return; Toast({ @@ -119,4 +193,4 @@ Page({ }); } }, -}); +}); \ No newline at end of file diff --git a/pages/usercenter/person-info/index.json b/pages/usercenter/person-info/index.json index e63dcc5..cac8792 100644 --- a/pages/usercenter/person-info/index.json +++ b/pages/usercenter/person-info/index.json @@ -7,6 +7,9 @@ "t-image": "/components/webp-image/index", "t-dialog": "tdesign-miniprogram/dialog/dialog", "t-toast": "tdesign-miniprogram/toast/toast", - "t-select-picker": "../components/ui-select-picker/index" + "t-select-picker": "../components/ui-select-picker/index", + "t-upload": "tdesign-miniprogram/upload/upload", + "t-avatar": "tdesign-miniprogram/avatar/avatar", + "t-input": "tdesign-miniprogram/input/input" } } \ No newline at end of file diff --git a/pages/usercenter/person-info/index.wxml b/pages/usercenter/person-info/index.wxml index 15f7aa3..8eac863 100644 --- a/pages/usercenter/person-info/index.wxml +++ b/pages/usercenter/person-info/index.wxml @@ -8,17 +8,10 @@ arrow t-class-left="order-group__left" > - + + - + - 切换账号登录 + 保存 { + request({ + url: `CustomerAddressApi/addOrUpdateCustomerAddress`, + method: 'POST', + data: data, + success: function (res) { + + resolve(res); + }, + fail: function (error) { + reject(error); + } + }); + }); +} \ No newline at end of file diff --git a/services/address/fetchAddress.js b/services/address/fetchAddress.js index 9525ab0..a514e5e 100644 --- a/services/address/fetchAddress.js +++ b/services/address/fetchAddress.js @@ -1,48 +1,42 @@ -import { config } from '../../config/index'; +import { + request +} from '../_utils/request'; -/** 获取收货地址 */ -function mockFetchDeliveryAddress(id) { - const { delay } = require('../_utils/delay'); - const { genAddress } = require('../../model/address'); - return delay().then(() => genAddress(id)); -} - -/** 获取收货地址 */ -export function fetchDeliveryAddress(id = 0) { - if (config.useMock) { - return mockFetchDeliveryAddress(id); - } - - return new Promise((resolve) => { - resolve('real api'); +/** 获取收货地址详情 */ +export function fetchDeliveryAddress(id) { + return new Promise((resolve, reject) => { + request({ + url: `CustomerAddressApi/getCustomerAddressDetails?CustomerAddressId=` + id, + method: 'GET', + success: function (res) { + let detail = res.data; + + resolve(detail); + }, + fail: function (error) { + reject(error); + } + }); }); } -/** 获取收货地址列表 */ -function mockFetchDeliveryAddressList(len = 0) { - const { delay } = require('../_utils/delay'); - const { genAddressList } = require('../../model/address'); - return delay().then(() => - genAddressList(len).map((address) => { - return { - ...address, - phoneNumber: address.phone, - address: `${address.provinceName}${address.cityName}${address.districtName}${address.detailAddress}`, - tag: address.addressTag, - }; - }), - ); -} /** 获取收货地址列表 */ -export function fetchDeliveryAddressList(len = 10) { - if (config.useMock) { - return mockFetchDeliveryAddressList(len); - } - - return new Promise((resolve) => { - resolve('real api'); +export function fetchDeliveryAddressList() { + return new Promise((resolve, reject) => { + request({ + url: `CustomerAddressApi/getCustomerAddressList`, + method: 'GET', + success: function (res) { + let list = res.data; + + resolve(list); + }, + fail: function (error) { + reject(error); + } + }); }); -} +} \ No newline at end of file diff --git a/services/address/getRegionTreeList.js b/services/address/getRegionTreeList.js new file mode 100644 index 0000000..1487975 --- /dev/null +++ b/services/address/getRegionTreeList.js @@ -0,0 +1,23 @@ +import { + request +} from '../_utils/request'; + + +/** 获取省市区树形列表 */ +export function getRegionTreeList() { + return new Promise((resolve, reject) => { + request({ + url: `RegionApi/getRegionTreeList`, + method: 'GET', + success: function (res) { + let list = res.data; + + resolve(list); + }, + fail: function (error) { + console.log(error,'报错'); + reject(error); + } + }); + }); +} \ No newline at end of file diff --git a/services/login/login.js b/services/login/login.js index b7f710b..d9fca32 100644 --- a/services/login/login.js +++ b/services/login/login.js @@ -8,25 +8,28 @@ import { /** 登录 */ export function login(data) { + return new Promise((resolve, reject) => { + request({ + url: `WeChatLogin/Login`, + method: 'POST', + data: data, + success: async function (res) { + setStorage('userInfo', res.data.user, 86400); + setStorage('Authorization', res.data.jwt, 86400); + const pages = getCurrentPages(); //获取小程序页面栈 + const beforePage = pages[pages.length - 1]; //获取上个页面的实例对象 -3是上上一个页面 + wx.navigateBack({ + delta: 1, + }); + beforePage.onLoad(); + wx.showToast({ + icon: 'success', + title: '登录成功', + }); + resolve(res); + }, + }); - request({ - url: `WeChatLogin/Login`, - method: 'POST', - data: data, - success: async function (res) { - setStorage('userInfo', res.data.user, 86400); - setStorage('Authorization', res.data.jwt, 86400); - const pages = getCurrentPages(); //获取小程序页面栈 - const beforePage = pages[pages.length - 1]; //获取上个页面的实例对象 -3是上上一个页面 - wx.navigateBack({ - delta: 2, - }); - beforePage.onLoad(); - wx.showToast({ - icon: 'success', - title: '登录成功', - }); - }, - }); + }) } \ No newline at end of file diff --git a/services/login/phone-register.js b/services/login/phone-register.js index 4cc8271..6338686 100644 --- a/services/login/phone-register.js +++ b/services/login/phone-register.js @@ -8,14 +8,16 @@ import { /** 发送验证码 */ export function sendPhoneCode(data) { + return new Promise((resolve, reject) => { + request({ + url: `WeChatLogin/sendPhoneCode`, + method: 'POST', + data: data, + success: async function (res) { - request({ - url: `WeChatLogin/sendPhoneCode`, - method: 'POST', - data: data, - success: async function (res) { - - }, - }); + resolve(res); + }, + }); + }) } \ No newline at end of file diff --git a/services/usercenter/fetchPerson.js b/services/usercenter/fetchPerson.js index bd31178..3af48d8 100644 --- a/services/usercenter/fetchPerson.js +++ b/services/usercenter/fetchPerson.js @@ -1,28 +1,32 @@ -import { config } from '../../config/index'; +import { + request +} from '../_utils/request'; +import { + getStorage +} from '~/utils/storage' +const userData = getStorage('userInfo'); -/** 获取个人中心信息 */ -function mockFetchPerson() { - const { delay } = require('../_utils/delay'); - const { genSimpleUserInfo } = require('../../model/usercenter'); - const { genAddress } = require('../../model/address'); - const address = genAddress(); - return delay().then(() => ({ - ...genSimpleUserInfo(), - address: { - provinceName: address.provinceName, - provinceCode: address.provinceCode, - cityName: address.cityName, - cityCode: address.cityCode, - }, - })); -} - -/** 获取个人中心信息 */ +/** 获取个人中心详情信息 */ export function fetchPerson() { - if (config.useMock) { - return mockFetchPerson(); - } - return new Promise((resolve) => { - resolve('real api'); + return new Promise((resolve, reject) => { + request({ + url: `CustomerApi/getCustomerDetails?CustomerGuid=` + userData?.customerGuid, + method: 'GET', + success: function (res) { + let personInfo = res.data; + let data = { + personInfo: { + avatarUrl: personInfo.customerAvatar, + nickName: personInfo.customerNickname, + phoneNumber: personInfo.customerMobilePhoneNumber, + gender : personInfo.customerGender, + } + }; + resolve(data); + }, + fail: function (error) { + reject(error); + } + }); }); -} +} \ No newline at end of file diff --git a/services/usercenter/set/logout.js b/services/usercenter/set/logout.js index b09fcbb..48a0346 100644 --- a/services/usercenter/set/logout.js +++ b/services/usercenter/set/logout.js @@ -17,17 +17,14 @@ export function logout() { removeStorage('userInfo') removeStorage('Authorization') - // 回到上一页 - const pages = getCurrentPages(); //获取小程序页面栈 - const beforePage = pages[pages.length - 1]; //获取上个页面的实例对象 -3是上上一个页面 - wx.navigateBack({ - delta: 2, - }); - beforePage.onLoad(); + // 回到首页 wx.showToast({ icon: 'success', title: '登出成功', }); + wx.reLaunch({ + url: '/pages/home/home' + }) resolve(res); }, fail: function (error) { diff --git a/services/usercenter/updatePerson.js b/services/usercenter/updatePerson.js new file mode 100644 index 0000000..e25088b --- /dev/null +++ b/services/usercenter/updatePerson.js @@ -0,0 +1,22 @@ +import { + request +} from '../_utils/request'; + + +/** 编辑个人资料 */ +export function updatePerson(data) { + return new Promise((resolve, reject) => { + request({ + url: `CustomerApi/UpdateCustomer`, + method: 'POST', + data: data, + success: function (res) { + + resolve(res); + }, + fail: function (error) { + reject(error); + } + }); + }); +} \ No newline at end of file diff --git a/style/theme.wxss b/style/theme.wxss index d1b46fb..8383f30 100644 --- a/style/theme.wxss +++ b/style/theme.wxss @@ -1,4 +1,8 @@ /* 主题定制 */ +.root-bg-color{ + background-color: #1989fa; +} + .t-input { --td-input-placeholder-text-color: #bbbbbb; --td-input-text-color: #333333; @@ -10,7 +14,7 @@ } .t-cascader { - --td-cascader-active-color: #fa4126; + --td-cascader-active-color: #1989fa; } .t-switch { @@ -21,13 +25,13 @@ --td-button-font-weight: 500; --td-button-medium-font-size: 32rpx; --td-button-default-color: #fff; - --td-button-default-bg-color: #fa4126; - --td-button-default-border-color: #fa4126; + --td-button-default-bg-color: #1989fa; + --td-button-default-border-color: #1989fa; --td-button-default-disabled-color: #fff; --td-button-default-disabled-bg: #cccccc; --td-button-default-disabled-border-color: #cccccc; - --td-button-default-active-bg-color: #fa4126; - --td-button-default-active-border-color: #fa4126; + --td-button-default-active-bg-color: #1989fa; + --td-button-default-active-border-color: #1989fa; } .t-textarea { @@ -35,11 +39,11 @@ } .t-checkbox { - --td-checkbox-icon-checked-color: #fa4126; + --td-checkbox-icon-checked-color: #1989fa; } .dialog__button-confirm { - color: #fa4126 !important; + color: #1989fa !important; } .dialog__button-cancel {