init
This commit is contained in:
parent
369aecfb32
commit
689843d7b7
@ -1,4 +0,0 @@
|
|||||||
#!/usr/bin/env sh
|
|
||||||
. "$(dirname -- "$0")/_/husky.sh"
|
|
||||||
|
|
||||||
npx --no-install commitlint --edit ""
|
|
@ -1,4 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
. "$(dirname "$0")/_/husky.sh"
|
|
||||||
|
|
||||||
npx lint-staged
|
|
@ -1,4 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
. "$(dirname "$0")/_/husky.sh"
|
|
||||||
|
|
||||||
exec < /dev/tty && npx git-cz --hook || true
|
|
11
.vscode/settings.json
vendored
11
.vscode/settings.json
vendored
@ -1,14 +1,14 @@
|
|||||||
{
|
{
|
||||||
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||||
"eslint.enable": true,
|
"eslint.enable": true,
|
||||||
"editor.formatOnSave": true,
|
"editor.formatOnSave": false,
|
||||||
"editor.codeActionsOnSave": {
|
"editor.codeActionsOnSave": {
|
||||||
"source.fixAll.tslint": true,
|
"source.fixAll.tslint": true,
|
||||||
"source.fixAll.eslint": true
|
"source.fixAll.eslint": true
|
||||||
},
|
},
|
||||||
"[javascript]": {
|
"[javascript]": {
|
||||||
"editor.formatOnSave": true,
|
"editor.formatOnSave": false,
|
||||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
"editor.defaultFormatter": "HookyQR.beautify"
|
||||||
},
|
},
|
||||||
"[json]": {
|
"[json]": {
|
||||||
"editor.defaultFormatter": "vscode.json-language-features"
|
"editor.defaultFormatter": "vscode.json-language-features"
|
||||||
@ -30,5 +30,8 @@
|
|||||||
"wrap_attributes_count": 4,
|
"wrap_attributes_count": 4,
|
||||||
"wrap_attributes_indent_size": 2
|
"wrap_attributes_indent_size": 2
|
||||||
},
|
},
|
||||||
"editor.tabSize": 2
|
"editor.tabSize": 2,
|
||||||
|
"[wxml]": {
|
||||||
|
"editor.defaultFormatter": "wechat.miniprogram.wxml-language-features"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
4
app.json
4
app.json
@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"pages": [
|
"pages": [
|
||||||
"pages/home/home",
|
"pages/home/home",
|
||||||
|
"pages/login/login",
|
||||||
"pages/usercenter/index",
|
"pages/usercenter/index",
|
||||||
"pages/usercenter/person-info/index",
|
"pages/usercenter/person-info/index",
|
||||||
"pages/usercenter/address/list/index",
|
"pages/usercenter/address/list/index",
|
||||||
@ -69,5 +70,8 @@
|
|||||||
"scope.userLocation": {
|
"scope.userLocation": {
|
||||||
"desc": "你的位置信息将用于小程序位置接口的效果展示"
|
"desc": "你的位置信息将用于小程序位置接口的效果展示"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"resolveAlias": {
|
||||||
|
"~/*": "/*"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { fetchHome } from '../../services/home/home';
|
import { fetchHome } from '~/services/home/home';
|
||||||
import { fetchGoodsList } from '../../services/good/fetchGoods';
|
import { fetchGoodsList } from '~/services/good/fetchGoods';
|
||||||
import Toast from 'tdesign-miniprogram/toast/index';
|
import Toast from 'tdesign-miniprogram/toast/index';
|
||||||
|
|
||||||
Page({
|
Page({
|
||||||
@ -13,8 +13,12 @@ Page({
|
|||||||
autoplay: true,
|
autoplay: true,
|
||||||
duration: '500',
|
duration: '500',
|
||||||
interval: 5000,
|
interval: 5000,
|
||||||
navigation: { type: 'dots' },
|
navigation: {
|
||||||
swiperImageProps: { mode: 'scaleToFill' },
|
type: 'dots',
|
||||||
|
},
|
||||||
|
swiperImageProps: {
|
||||||
|
mode: 'scaleToFill',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
goodListPagination: {
|
goodListPagination: {
|
||||||
@ -80,7 +84,9 @@ Page({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setData({ goodsListLoadStatus: 1 });
|
this.setData({
|
||||||
|
goodsListLoadStatus: 1,
|
||||||
|
});
|
||||||
|
|
||||||
const pageSize = this.goodListPagination.num;
|
const pageSize = this.goodListPagination.num;
|
||||||
let pageIndex = this.privateData.tabIndex * pageSize + this.goodListPagination.index + 1;
|
let pageIndex = this.privateData.tabIndex * pageSize + this.goodListPagination.index + 1;
|
||||||
@ -98,7 +104,9 @@ Page({
|
|||||||
this.goodListPagination.index = pageIndex;
|
this.goodListPagination.index = pageIndex;
|
||||||
this.goodListPagination.num = pageSize;
|
this.goodListPagination.num = pageSize;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.setData({ goodsListLoadStatus: 3 });
|
this.setData({
|
||||||
|
goodsListLoadStatus: 3,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -119,7 +127,9 @@ Page({
|
|||||||
},
|
},
|
||||||
|
|
||||||
navToSearchPage() {
|
navToSearchPage() {
|
||||||
wx.navigateTo({ url: '/pages/goods/search/index' });
|
wx.navigateTo({
|
||||||
|
url: '/pages/goods/search/index',
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
navToActivityDetail({ detail }) {
|
navToActivityDetail({ detail }) {
|
||||||
|
141
pages/login/login.js
Normal file
141
pages/login/login.js
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
// pages/login/login.js
|
||||||
|
const app = getApp();
|
||||||
|
|
||||||
|
Page({
|
||||||
|
/**
|
||||||
|
* 页面的初始数据
|
||||||
|
*/
|
||||||
|
data: {
|
||||||
|
back: true,
|
||||||
|
code: '',
|
||||||
|
},
|
||||||
|
login() {
|
||||||
|
var that = this;
|
||||||
|
wx.getUserProfile({
|
||||||
|
//获取用户信息。页面产生点击事件(例如 button 上 bindtap 的回调中)后才可调用,每次请求都会弹出授权窗口,用户同意后返回 userInfo,用于替换 wx.getUserInfo
|
||||||
|
lang: 'zh_CN',
|
||||||
|
desc: '用于在后台更好的识别您的身份', //声明获取用户个人信息后的用途
|
||||||
|
success(user) {
|
||||||
|
//接口调用成功的回调函数
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
encryptedData: user.encryptedData,
|
||||||
|
iv: user.iv,
|
||||||
|
// signature: user.signature,
|
||||||
|
// rawData: user.rawData,
|
||||||
|
code: that.data.code,
|
||||||
|
};
|
||||||
|
// console.log(data);
|
||||||
|
|
||||||
|
app.request({
|
||||||
|
url: `login`,
|
||||||
|
method: 'POST',
|
||||||
|
data: data,
|
||||||
|
success: async function (res) {
|
||||||
|
// wx.setStorageSync('userInfo', res);
|
||||||
|
app.put('userInfo', res, 86400);
|
||||||
|
const userInfo = app.get('userInfo');
|
||||||
|
|
||||||
|
// 如果第一次登录就注册一个客户账号
|
||||||
|
app.request({
|
||||||
|
url: `login/addCustomer`,
|
||||||
|
method: 'POST',
|
||||||
|
data: {
|
||||||
|
CustomerId: 0,
|
||||||
|
CustomerGuid: 0,
|
||||||
|
CustomerXcxOpenid: userInfo.openId,
|
||||||
|
CustomerXcxName: userInfo.nickName,
|
||||||
|
CustomerXcxImg: userInfo.avatarUrl,
|
||||||
|
CustomerSex: userInfo.gender,
|
||||||
|
},
|
||||||
|
success(res) {
|
||||||
|
app.put('Authorization', res.data, 86400);
|
||||||
|
|
||||||
|
const pages = getCurrentPages(); //获取小程序页面栈
|
||||||
|
const beforePage = pages[pages.length - 2]; //获取上个页面的实例对象 -3是上上一个页面
|
||||||
|
that.setData({
|
||||||
|
back: false,
|
||||||
|
});
|
||||||
|
wx.navigateBack({
|
||||||
|
delta: 2,
|
||||||
|
});
|
||||||
|
beforePage.onLoad();
|
||||||
|
// console.log(wx.getStorageSync('userInfo'));
|
||||||
|
wx.showToast({
|
||||||
|
icon: 'success',
|
||||||
|
title: '登录成功',
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
fail() {
|
||||||
|
wx.switchTab({
|
||||||
|
url: '/pages/home/home',
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 生命周期函数--监听页面加载
|
||||||
|
*/
|
||||||
|
onLoad() {
|
||||||
|
var that = this;
|
||||||
|
|
||||||
|
wx.login({
|
||||||
|
success(res) {
|
||||||
|
that.setData({
|
||||||
|
code: res.code,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生命周期函数--监听页面初次渲染完成
|
||||||
|
*/
|
||||||
|
onReady() {},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生命周期函数--监听页面显示
|
||||||
|
*/
|
||||||
|
onShow() {},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生命周期函数--监听页面隐藏
|
||||||
|
*/
|
||||||
|
onHide() {},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生命周期函数--监听页面卸载
|
||||||
|
*/
|
||||||
|
onUnload() {
|
||||||
|
var that = this;
|
||||||
|
//设置缓存允许下次跳转登录页
|
||||||
|
wx.setStorage({
|
||||||
|
key: 'isshowLogin',
|
||||||
|
data: false,
|
||||||
|
});
|
||||||
|
if (that.data.back === true) {
|
||||||
|
wx.reLaunch({
|
||||||
|
url: '/pages/home/home',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 页面相关事件处理函数--监听用户下拉动作
|
||||||
|
*/
|
||||||
|
onPullDownRefresh() {},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 页面上拉触底事件的处理函数
|
||||||
|
*/
|
||||||
|
onReachBottom() {},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户点击右上角分享
|
||||||
|
*/
|
||||||
|
onShareAppMessage() {},
|
||||||
|
});
|
4
pages/login/login.json
Normal file
4
pages/login/login.json
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"usingComponents": {},
|
||||||
|
"navigationBarTitleText": "授权登录"
|
||||||
|
}
|
8
pages/login/login.wxml
Normal file
8
pages/login/login.wxml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<!--pages/login/login.wxml-->
|
||||||
|
<!-- <header backOptional="true">授权登录</header> -->
|
||||||
|
<view class="loginBox">
|
||||||
|
<view class="title">授权登录</view>
|
||||||
|
<view class="NeedText">快转铺请求授权以下消息</view>
|
||||||
|
<view class="NeedLabel"><view></view>获取您的公开信息(名称、头像等)</view>
|
||||||
|
<view class="button" bindtap="login">授权名称/头像</view>
|
||||||
|
</view>
|
44
pages/login/login.wxss
Normal file
44
pages/login/login.wxss
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
/* pages/login/login.wxss */
|
||||||
|
page{
|
||||||
|
background-color: black;
|
||||||
|
}
|
||||||
|
.loginBox{
|
||||||
|
width: 75%;
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 30rpx;
|
||||||
|
margin-top: 50%;
|
||||||
|
background-color: white;
|
||||||
|
}
|
||||||
|
.loginBox .title{
|
||||||
|
width: 100%;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 38rpx;
|
||||||
|
font-weight: 600;
|
||||||
|
margin-bottom: 5rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.loginBox .NeedLabel{
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
color: rgb(190, 190, 190);
|
||||||
|
font-size: 30rpx;
|
||||||
|
margin: 15rpx 0;
|
||||||
|
}
|
||||||
|
.NeedLabel view{
|
||||||
|
width: 15rpx;
|
||||||
|
height: 15rpx;
|
||||||
|
border-radius: 50%;
|
||||||
|
margin-right: 15rpx;
|
||||||
|
background-color: rgb(190, 190, 190);
|
||||||
|
}
|
||||||
|
.loginBox .button{
|
||||||
|
width: 100%;
|
||||||
|
text-align: center;
|
||||||
|
padding: 25rpx 0;
|
||||||
|
border-radius: 15rpx;
|
||||||
|
color: white;
|
||||||
|
font-size: 36rpx;
|
||||||
|
background-color: rgb(30, 153, 30);
|
||||||
|
}
|
65
services/_utils/request.js
Normal file
65
services/_utils/request.js
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
const ServerBasePath = 'https://localhost:8888/api/';
|
||||||
|
|
||||||
|
// 网络请求封装
|
||||||
|
export function request(option) {
|
||||||
|
const that = this;
|
||||||
|
const { url } = option;
|
||||||
|
const { data } = option;
|
||||||
|
const { fail } = option;
|
||||||
|
const { success } = option;
|
||||||
|
const { method } = option;
|
||||||
|
|
||||||
|
wx.showLoading({
|
||||||
|
title: '数据加载中',
|
||||||
|
mask: true,
|
||||||
|
});
|
||||||
|
wx.request(
|
||||||
|
(option,
|
||||||
|
{
|
||||||
|
header: {
|
||||||
|
Authorization: `Bearer ${that.get('Authorization')}`,
|
||||||
|
},
|
||||||
|
timeout: 30000, //设置超时时间
|
||||||
|
url: ServerBasePath + url,
|
||||||
|
data: data,
|
||||||
|
method: method,
|
||||||
|
success: function (res) {
|
||||||
|
// var pages = getCurrentPages(); // 获取页面指针数组
|
||||||
|
// var currentPage = pages[pages.length - 2]; // 获取当前页
|
||||||
|
if (res.data.Code === 401) {
|
||||||
|
const userInfo = that.get('userInfo');
|
||||||
|
//初次跳转登录页
|
||||||
|
if (!userInfo) {
|
||||||
|
wx.navigateTo({
|
||||||
|
url: '/pages/login/login',
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof success === 'function') {
|
||||||
|
if (res.statusCode === 200) {
|
||||||
|
success(res.data, res);
|
||||||
|
wx.hideLoading();
|
||||||
|
} else {
|
||||||
|
wx.showToast({
|
||||||
|
icon: 'error',
|
||||||
|
title: '网络异常,请重试',
|
||||||
|
});
|
||||||
|
wx.hideLoading();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fail: function (res) {
|
||||||
|
if (typeof fail === 'function') {
|
||||||
|
fail(res);
|
||||||
|
}
|
||||||
|
wx.showToast({
|
||||||
|
icon: 'error',
|
||||||
|
title: '网络异常,请重试',
|
||||||
|
});
|
||||||
|
console.log(`请求:【${url}】fail`, res);
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
@ -1,9 +1,9 @@
|
|||||||
import { config, cdnBase } from '../../config/index';
|
import { config, cdnBase } from '~/config/index';
|
||||||
|
|
||||||
/** 获取首页数据 */
|
/** 获取首页数据 */
|
||||||
function mockFetchHome() {
|
function mockFetchHome() {
|
||||||
const { delay } = require('../_utils/delay');
|
const { delay } = require('~/services/_utils/delay');
|
||||||
const { genSwiperImageList } = require('../../model/swiper');
|
const { genSwiperImageList } = require('~/model/swiper');
|
||||||
return delay().then(() => {
|
return delay().then(() => {
|
||||||
return {
|
return {
|
||||||
swiper: genSwiperImageList(),
|
swiper: genSwiperImageList(),
|
||||||
|
1
services/login/login.js
Normal file
1
services/login/login.js
Normal file
@ -0,0 +1 @@
|
|||||||
|
// import { request } from '../_utils/request';
|
58
utils/storage.js
Normal file
58
utils/storage.js
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
/**
|
||||||
|
* 设置存储
|
||||||
|
* k 键key
|
||||||
|
* v 值value
|
||||||
|
* t 秒
|
||||||
|
*/
|
||||||
|
function setStorage(k, v, t) {
|
||||||
|
wx.setStorageSync(k, v);
|
||||||
|
var seconds = parseInt(t);
|
||||||
|
if (seconds > 0) {
|
||||||
|
var newtime = Date.parse(new Date());
|
||||||
|
newtime = newtime / 1000 + seconds;
|
||||||
|
wx.setStorageSync(k + redis, `${newtime}`);
|
||||||
|
} else {
|
||||||
|
wx.removeStorageSync(k + redis);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取存储
|
||||||
|
* k 键key
|
||||||
|
*/
|
||||||
|
function getStorage(k) {
|
||||||
|
var deadtime = parseInt(wx.getStorageSync(k + redis));
|
||||||
|
if (deadtime) {
|
||||||
|
if (parseInt(deadtime) < Date.parse(new Date()) / 1000) {
|
||||||
|
wx.removeStorageSync(k);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var res = wx.getStorageSync(k);
|
||||||
|
if (res) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除存储
|
||||||
|
*/
|
||||||
|
function removeStorage(k) {
|
||||||
|
wx.removeStorageSync(k);
|
||||||
|
wx.removeStorageSync(k + redis);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清除所有存储
|
||||||
|
*/
|
||||||
|
function clear() {
|
||||||
|
wx.clearStorageSync();
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
setStorage,
|
||||||
|
getStorage,
|
||||||
|
removeStorage,
|
||||||
|
clear,
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user