Commit 4ec29ce2 by xinla

uniapp基础配置

1 parent dcb81287
...@@ -21,3 +21,5 @@ logs ...@@ -21,3 +21,5 @@ logs
.m2 .m2
linkwe-pc/pc/ linkwe-pc/pc/
linkwe-mobile/h5/ linkwe-mobile/h5/
linkwe-uniapp/unpackage/dist/
linkwe-uniapp/js_sdk/
\ No newline at end of file \ No newline at end of file
{ // launch.json 配置了启动调试时相关设置,configurations下节点名称可为 app-plus/h5/mp-weixin/mp-baidu/mp-alipay/mp-qq/mp-toutiao/mp-360/
// launchtype项可配置值为local或remote, local代表前端连本地云函数,remote代表前端连云端云函数
"version": "0.0",
"configurations": [{
"default" :
{
"launchtype" : "local"
},
"mp-weixin" :
{
"launchtype" : "local"
},
"type" : "uniCloud"
}
]
}
<script> <script>
export default { export default {
onLaunch: function() { onLaunch: function () {
console.log('App Launch') console.log('App Launch')
}, },
onShow: function() { onShow: function () {
console.log('App Show') console.log('App Show')
}, },
onHide: function() { onHide: function () {
console.log('App Hide') console.log('App Hide')
} },
} }
</script> </script>
<style> <style>
/*每个页面公共css */ /*每个页面公共css */
@import url(@/styles/common.css);
</style> </style>
import request from '@/utils/request.js'
import config from '@/config.js'
const service = config.services.wecom + '/short/link'
// 智能短链
// 列表
export function getList(data) {
return request({
url: service + '/list',
params: data,
})
}
// 详情
export function getDetail(id) {
return request({
url: service + '/get/' + id,
})
}
// 删除
export function remove(id) {
return request({
url: service + '/delete/' + id,
method: 'DELETE',
})
}
// 新增
export function add(data) {
return request({
url: service + '/add',
method: 'POST',
data,
})
}
// 修改
export function update(data) {
return request({
url: service + '/update/' + id,
method: 'PUT',
data,
})
}
module.exports = {
BASE_API: 'http://dev.linkwechat.net/linkwechat-dev-api',
// BASE_API: 'http://demo.linkwechat.net/linkwechat-api',
services: {
common: '/common',
wecom: '/open',
}
}
@charset "utf-8";
* {
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
/**,*:before,*:after{-moz-box-sizing: border-box;-webkit-box-sizing: border-box;box-sizing: border-box;-webkit-tap-highlight-color: rgba(0,0,0,0);-webkit-tap-highlight-color: transparent;max-height: 100000px;}*/
body,
h1,
h2,
h3,
h4,
h5,
h6,
hr,
p,
blockquote,
dl,
dt,
dd,
ul,
ol,
li,
pre,
form,
fieldset,
legend,
button,
input,
textarea,
th,
td {
margin: 0;
padding: 0;
}
body,input, select, textarea /* for ie */ {
font: 14px "PingFang SC", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Helvetica, Arial, "Hiragino Sans GB", "Source Han Sans", "Noto Sans CJK Sc", "Microsoft YaHei", "Microsoft Jhenghei", sans-serif;
line-height: 1.15;
color: #333; /*touch-action: none*/
background: #fff;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
} /** 设置默认字体 **/
header,
section,
footer,
aside,
nav,
article,
figure {
display: block;
}
input,
button,
select,
textarea {
outline: none;
vertical-align: middle; /*解决父级底部多余空白*/
-webkit-appearance: none; /*去掉webkit默认的表单样式*/
font-size: 100%; /* 使得表单元素在 ie 下能继承字体大小 */
border: none;
background: none;
color: inherit;
}
address,
cite,
dfn,
em,
var {
font-style: normal;
} /* 将斜体扶正 , 注:optgroup 无法扶正 */
h1,
h2,
h3,
h4,
h5,
h6 {
font-size: 100%;
background: none;
}
code,
kbd,
pre,
samp {
font-family: courier new, courier, monospace;
} /* 统一等宽字体 */
object,
embed,
video {
max-width: 100%;
}
a:link,
a:active,
a:visited,
a:hover {
text-decoration: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
img {
border: 0;
max-width: 100%;
vertical-align: middle;
} /*解决父级底部多余空白*/
small {
font-size: 12px;
} /* 小于 12px 的中文很难阅读,让 small 正常化 */
legend {
color: #000;
} /*for ie6*/
fieldset {
border: 0;
}
li {
list-style: none;
}
a {
color: inherit;
}
/*click outline for firefox*/
button::-moz-focus-inner,
input[type='reset']::-moz-focus-inner,
input[type='button']::-moz-focus-inner,
input[type='submit']::-moz-focus-inner,
input[type='file'] > input[type='button']::-moz-focus-inner {
border: none;
}
/*click outline for IE and other browser*/
button:focus,
input[type='reset']:focus,
input[type='button']:focus,
input[type='submit']:focus,
input[type='file'] > input[type='button']:focus {
outline: none;
}
/* 注意此处合并写法无效 */
input::-webkit-input-placeholder,
textarea::-webkit-input-placeholder {
color: #fff;
font-size: 16px;
}
input::-moz-placeholder,
textarea::-moz-placeholder {
color: #fff;
font-size: 16px;
}
input:-ms-input-placeholder,
textarea:-ms-input-placeholder {
color: #fff;
font-size: 16px;
}
*:not(input, select, textarea) {
-webkit-user-select: none;
} /*禁止选中文本内容*/
::-webkit-scrollbar {
/*滚动条整体样式*/
width: 2px; /*高宽分别对应横竖滚动条的尺寸*/
height: 2px;
}
::-webkit-scrollbar-thumb {
/*滚动条里面小方块*/
border-radius: 2px;
/*深色模式*/
/* -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2); */
background: #bbb;
/*浅色模式*/
/*-webkit-box-shadow: 0 0 3px rgba(0, 0, 0, 0.2);
background: rgb(245, 245, 245);
border: 1px solid #333;
border-bottom-width: 2px;*/
}
::-webkit-scrollbar-track {
/*滚动条里面轨道*/
display: none;
-webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
border-radius: 2px;
background: #eee;
}
/* common class */
/*bfc model*/
.bfc-o {
overflow: hidden;
position: relative;
}
.bfc-d {
display: inline-block;
vertical-align: top;
position: relative;
}
.bfc-p {
position: absolute;
}
.fl {
float: left;
position: relative;
}
.fr {
float: right;
position: relative;
}
.flex {
display: flex;
}
.fxbw {
display: flex;
align-items: flex-start;
justify-content: space-between;
}
ais {
align-items: stretch;
}
.aic {
align-items: center;
}
.al {
text-align: left;
}
.ac {
text-align: center;
}
.ar {
text-align: right;
}
.hide {
display: none;
}
.blod {
font-weight: bold;
}
/*top-fixed and bottom-fixed*/
.tf,
.bf {
position: fixed;
width: 100%;
height: 50px;
z-index: 999;
}
.tf {
top: 0;
}
.bf {
bottom: 0;
}
/*mask*/
.mask {
position: fixed;
width: 100%;
height: 100%;
background: rgba(39, 39, 39, 0.76);
left: 0;
bottom: 0;
margin: auto;
z-index: 9;
}
/*center-center*/
.cc {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
/*t-o-h-e*/
.toe {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.line2-toe {
text-overflow: -o-ellipsis-lastline;
overflow: hidden;
text-overflow: ellipsis;
word-break: break-all;
display: -webkit-box;
white-space: pre-wrap;
-webkit-line-clamp: 2;
line-clamp: 2;
-webkit-box-orient: vertical;
}
/*close*/
.close {
position: relative;
float: right;
width: 20px;
height: 20px;
line-height: 20px;
background: #f8f8f8;
text-align: center;
cursor: pointer;
}
/* pc frame */
.wrapper {
position: relative;
max-width: 1920px;
min-width: 1020px;
margin: 0 auto;
padding: 0 15px;
overflow: hidden;
}
.cp {
cursor: pointer;
}
.pt5 {
padding-top: 5px;
}
.pr5 {
padding-right: 5px;
}
.pb5 {
padding-bottom: 5px;
}
.pl5 {
padding-left: 5px;
}
.pad5 {
padding: 5px;
}
.pt10 {
padding-top: 10px;
}
.pr10 {
padding-right: 10px;
}
.pb10 {
padding-bottom: 10px;
}
.pl10 {
padding-left: 10px;
}
.pad10 {
padding: 10px;
}
.pt20 {
padding-top: 20px;
}
.pr20 {
padding-right: 20px;
}
.pb20 {
padding-bottom: 20px;
}
.pl20 {
padding-left: 20px;
}
.pad20 {
padding: 20px;
}
.mt5 {
margin-top: 5px;
}
.mr5 {
margin-right: 5px;
}
.mb5 {
margin-bottom: 5px;
}
.ml5 {
margin-left: 5px;
}
.mar5 {
margin: 5px;
}
.mb8 {
margin-bottom: 8px;
}
.mt10 {
margin-top: 10px;
}
.mr10 {
margin-right: 10px;
}
.mb10 {
margin-bottom: 10px;
}
.ml10 {
margin-left: 10px;
}
.mar10 {
margin: 10px;
}
.mt15 {
margin-top: 15px;
}
.mr15 {
margin-right: 15px;
}
.mb15 {
margin-bottom: 15px;
}
.ml15 {
margin-left: 15px;
}
.ml15 {
margin-left: 15px;
}
.mt20 {
margin-top: 20px;
}
.mr20 {
margin-right: 20px;
}
.mb20 {
margin-bottom: 20px;
}
.ml20 {
margin-left: 20px;
}
.mar20 {
margin: 20px;
}
/* Dark mode */
@media (prefers-color-scheme: dark) {
body,img,video {
filter: invert(1) hue-rotate(180deg);
}
/* 不使用暗黑模式 */
.no-dark {
position: relative;
}
.no-dark::before{
content: " ";
position: absolute;
display: block;
height: 100%;
width: 100%;
backdrop-filter: invert(1) hue-rotate(180deg);
}
}
\ No newline at end of file \ No newline at end of file
/**
* query请求路径参数转为对象
* @param {*} url
*/
export function param2Obj (url) {
try {
url = url == null ? window.location.href : url
let search = decodeURIComponent(url)
.split('?')
.slice(1)
if (!search[0]) {
return
}
search = search.filter((e) => e.includes('=')).map((e) => e.split('#')[0])
search = search.join('&')
return JSON.parse(
'{"' +
search
.replace(/"/g, '\\"')
.replace(/&/g, '","')
.replace(/=/g, '":"') +
'"}'
)
} catch (error) {
alert(error)
}
// 更完善的方案
// url = url == null ? window.location.href : url
// const search = url.substring(url.lastIndexOf('?') + 1)
// search = search && search.split('#')[0]
// if (!search) {
// return {}
// }
// const obj = {}
// const reg = /([^?&=]+)=([^?&=]*)/g
// search.replace(reg, (rs, $1, $2) => {
// const name = decodeURIComponent($1)
// let val = decodeURIComponent($2)
// val = String(val)
// obj[name] = val
// return rs
// })
// return obj
}
/**
* Obj转为路径query请求参数
* @param {*} obj
*/
export function obj2query (obj) {
if (!obj) return ''
return Object.keys(obj)
.map((key) => {
if (obj[key] === undefined) return ''
return key + '=' + obj[key]
})
.filter((e) => !!e)
.join('&')
}
/**
* 获取query请求参数中name对应的值
* @param string name
*/
export function getQueryValue (name, str) {
try {
let url = str || window.location.href
// let search = url.split('?')[1]
// search = search && search.split('#')[0]
// if (!search) {
// return ''
// }
let reg = new RegExp('(^|&|\\?)' + name + '=([^&#]*)(&|#|$)')
let r = url.match(reg)
if (r != null) {
return decodeURIComponent(r[2])
}
return ''
} catch (error) {
alert(error)
}
}
export function urlReplaceFirstHistory (url) {
window.history.go(-(window.history.length - 1))
window.location.replace(url)
}
import { getUserOpenid, getWechatUserInfo, getWxRedirect, wxLogin } from '@/api/common'
// 微信端授权登录
export async function getWxCode () {
let userinfo = sessionStorage.getItem('userinfo')
//取缓存中的用户信息
if (userinfo) {
try {
userinfo = JSON.parse(userinfo)
} catch (error) {
// alert(error)
}
return userinfo
}
let code = getQueryValue('code') //是否存在code
if (!code) {
let url = (await getWxRedirect()).data
let id = getQueryValue('appid', url)
sessionStorage.setItem('weAppId', id)
window.location.href = url
}
try {
if (code) {
let { data: dataLogin } = await wxLogin(code)
sessionStorage.setItem('token', dataLogin.access_token)
let { data: dataUser } = await getWechatUserInfo()
sessionStorage.setItem('userinfo', JSON.stringify(dataUser))
return dataUser
}
} catch (error) {
return Promise.reject()
}
}
// 日期时间格式化
export function dateFormat (dateString, fmt = 'yyyy-MM-dd hh:mm:ss') {
if (!dateString) {
return
}
var date = dateString
if (Object.prototype.toString.call(dateString) !== '[object Date]') {
if (!dateString.includes('T')) {
dateString = dateString.replace(/-/g, '/')
}
date = new Date(dateString)
}
var o = {
'M+': date.getMonth() + 1, //月份
'd+': date.getDate(), //日
'h+': date.getHours(), //小时
'm+': date.getMinutes(), //分
's+': date.getSeconds(), //秒
'q+': Math.floor((date.getMonth() + 3) / 3), //季度
'S+': date.getMilliseconds(), //毫秒
'w+': '星期' + '日一二三四五六'.charAt(date.getDay()), //星期
}
if (/(y+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
}
for (var k in o) {
if (new RegExp('(' + k + ')').test(fmt)) {
fmt = fmt.replace(
RegExp.$1,
RegExp.$1.length == 1 || String(o[k]).length > 1 ? o[k] : '0' + o[k]
)
}
}
return fmt
}
export function stringifyError () {
Error.prototype.toJSON = function () {
return this.toString()
}
}
export function baiduMapError (type) {
let arr = [
{ code: 0, value: '检索成功' },
{ code: 1, value: '城市列表' },
{ code: 2, value: '位置结果未知' },
{ code: 3, value: '导航结果未知' },
{ code: 4, value: '非法密钥AK' },
{ code: 5, value: '非法请求' },
{ code: 6, value: '没有权限, 请确认手机是否打开定位服务!' },
{ code: 7, value: '服务不可用' },
{ code: 8, value: '超时' },
]
let str
arr.forEach(dd => {
if (dd.code === type) {
str = dd.value
}
})
return str
}
export function splitName (str) {
if (str) {
let area = {}
let index11 = 0
let index1 = str.indexOf("省")
if (index1 == -1) {
index11 = str.indexOf("自治区")
if (index11 != -1) {
area.Province = str.substring(0, index11 + 3)
} else {
area.Province = str.substring(0, 0)
}
} else {
area.Province = str.substring(0, index1 + 1)
}
let index2 = str.indexOf("市")
if (index11 == -1) {
area.City = str.substring(index11 + 1, index2 + 1)
} else {
if (index11 == 0) {
area.City = str.substring(index1 + 1, index2 + 1)
} else {
area.City = str.substring(index11 + 3, index2 + 1)
}
}
let index3 = str.indexOf("区")
if (index3 == -1) {
index3 = str.indexOf("县")
if (index3 == -1) {
index3 = str.indexOf('旗')
area.Country = str.substring(index2 + 1, index3 + 1)
} else {
area.Country = str.substring(index2 + 1, index3 + 1)
}
} else {
area.Country = str.substring(index2 + 1, index3 + 1)
}
return [area.Province, area.City, area.Country]
} else {
return ''
}
}
\ No newline at end of file \ No newline at end of file
import Request from '@/js_sdk/luch-request/index.js'
import cfg from '@/config.js'
const http = new Request()
http.interceptors.request.use((config) => { // 可使用async await 做异步操作
// config.header = {
// ...config.header,
// a: 1 // 演示拦截器header加参
// }
// 演示custom 用处
// if (config.custom.auth) {
// config.header.token = 'token'
// }
// if (config.custom.loading) {
// uni.showLoading()
// }
/**
/* 演示
if (!token) { // 如果token不存在,return Promise.reject(config) 会取消本次请求
return Promise.reject(config)
}
**/
return config
}, config => { // 可使用async await 做异步操作
return Promise.reject(config)
})
http.interceptors.response.use((response) => {
/* 对响应成功做点什么 可使用async await 做异步操作*/
let data = response.data
if (data.code == 200 || data.code != 0 && data.code != 500) {
return data.result || data.record || data.data
}
uni.hideLoading();
uni.showToast({
icon: 'none',
title: data.msg,
duration: 2000
})
return Promise.reject(response) // return Promise.reject 可使promise状态进入catch
}, (response) => {
/* 对响应错误做点什么 (statusCode !== 200)*/
console.log(response)
return Promise.reject(response)
})
export async function post(url, data) {
return http.request({
method: 'POST', // 请求方法必须大写
url,
data,
})
}
export async function get(url, params) {
return http.get(url, {
params,
})
}
export default function(config = {
method: 'get'
}) {
config.baseURL = cfg.BASE_API
if (config.method.toLowerCase() === 'get' && !config.params) {
config.params = config.data
}
return request(config)
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!