master
lion 3 years ago
parent 5c73fdfe92
commit 3a1d0815c0

@ -23,17 +23,15 @@
</view>
<view v-else>
<view v-for="(item,indexkey) in itemList" :key="indexkey">
<view class="listitem u-body-item u-border-bottom u-col-between u-p-t-0">
<view class="titles">
<view class="u-body-item-title u-line-2">{{item.title}}</view>
<view :class="current==0?'titles titles100':'titles'">
<view class="u-body-item-title u-line-2">{{item.title}}{{current}}</view>
<view class="times">{{item.times}}</view>
</view>
<image v-if="current==0" width="100%" :src="item.imgs" mode=""></image>
</view>
</view>
</view>
</scroll-view>
</swiper-item>
</swiper>
@ -45,7 +43,7 @@
props:{
tabs:{
type: Array,
default: ()=>[[],[],[],[],[],[]]
default: ()=>[[],[],[],[],[],[],[],[]]
},
currentPage:{
type:Number,
@ -72,6 +70,10 @@
}, {
name: '综合新闻'
}, {
name: '市局通知'
},{
name: '市局文件'
},{
name: '各地警讯'
}, {
name: '机关动态'
@ -144,10 +146,13 @@
}
.titles{
width:70%;
width:100%;
display: inline-block;
vertical-align: top;
}
.titles100{
width:70%;
}
/deep/ .titles .u-body-item-title{
height:96rpx;
}

@ -27,9 +27,11 @@ Vue.prototype.util = util;
import subtabBar from 'components/tabbar/subtabbar.vue'
Vue.component('subtabBar', subtabBar)
// import subtabBar from 'components/tabbar/subtabbar.vue'
// Vue.component('subtabBar', subtabBar)
import tabBar from 'components/tabbar/tabbar.vue'
Vue.component('tabBar', tabBar)
import top from 'components/top/top.vue'
Vue.component('topBar', top)
import menubar from 'components/menubar/menubar.vue'
Vue.component('menuBar', menubar)
Vue.component('menuBar', menubar)

@ -1,72 +1,89 @@
{
"name" : "常州公安-手机端",
"appid" : "__UNI__EDB3F98",
"description" : "",
"versionName" : "1.0.0",
"versionCode" : "100",
"transformPx" : false,
/* 5+App */
"app-plus" : {
"usingComponents" : true,
"nvueStyleCompiler" : "uni-app",
"compilerVersion" : 3,
"splashscreen" : {
"alwaysShowBeforeRender" : true,
"waiting" : true,
"autoclose" : true,
"delay" : 0
},
/* */
"modules" : {},
/* */
"distribute" : {
/* android */
"android" : {
"permissions" : [
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
"<uses-permission android:name=\"android.permission.READ_LOGS\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>",
"<uses-feature android:name=\"android.hardware.camera.autofocus\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.CAMERA\"/>",
"<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>",
"<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>",
"<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>",
"<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>",
"<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>",
"<uses-feature android:name=\"android.hardware.camera\"/>",
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
]
},
/* ios */
"ios" : {},
/* SDK */
"sdkConfigs" : {}
}
},
/* */
"quickapp" : {},
/* */
"mp-weixin" : {
"appid" : "",
"setting" : {
"urlCheck" : false
},
"usingComponents" : true
},
"mp-alipay" : {
"usingComponents" : true
},
"mp-baidu" : {
"usingComponents" : true
},
"mp-toutiao" : {
"usingComponents" : true
},
"uniStatistics" : {
"enable" : false
},
"vueVersion" : "2"
{
"name": "常州公安-手机端",
"appid": "__UNI__EDB3F98",
"description": "",
"versionName": "1.0.0",
"versionCode": "100",
"transformPx": false,
/* 5+App */
"app-plus": {
"usingComponents": true,
"nvueStyleCompiler": "uni-app",
"compilerVersion": 3,
"splashscreen": {
"alwaysShowBeforeRender": true,
"waiting": true,
"autoclose": true,
"delay": 0
},
/* */
"modules": {},
/* */
"distribute": {
/* android */
"android": {
"permissions": [
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
"<uses-permission android:name=\"android.permission.READ_LOGS\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>",
"<uses-feature android:name=\"android.hardware.camera.autofocus\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.CAMERA\"/>",
"<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>",
"<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>",
"<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>",
"<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>",
"<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>",
"<uses-feature android:name=\"android.hardware.camera\"/>",
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
]
},
/* ios */
"ios": {},
/* SDK */
"sdkConfigs": {}
}
},
/* */
"quickapp": {},
/* */
"mp-weixin": {
"appid": "",
"setting": {
"urlCheck": false
},
"usingComponents": true
},
"mp-alipay": {
"usingComponents": true
},
"mp-baidu": {
"usingComponents": true
},
"mp-toutiao": {
"usingComponents": true
},
"uniStatistics": {
"enable": false
},
"vueVersion": "2",
"h5":{
"devServer": {
"port" : 8081, //
"disableHostCheck" : true,
"proxy": {
"": {
"target":"http://czga.langye.net/e/extend/api/index.php",
"changeOrigin": true,//
"secure": false
}
}
},
"router" : {
"base" : "/"
}
}
}

@ -6,7 +6,7 @@
<view class='borderwrap' >
<!-- 导航6个 -->
<u-row gutter="12" justify="around">
<u-col span="4" v-for="item in imgList" @click="changeItem(item)">
<u-col span="3" v-for="item in imgList" @click="changeItem(item)">
<u-image width="107rpx" height="113rpx" :src="item.src"></u-image>
<view>{{item.title}}</view>
</u-col>
@ -57,11 +57,7 @@
</template>
<script>
import tabBar from '@/components/tabbar/tabbar.vue'
export default {
components: {
tabBar
},
data() {
return {
cardCon:{
@ -78,27 +74,43 @@
imgList: [{
title: "图片新闻",
src: "/static/images/tpxw.png",
path: "/pages/list/tpxw"
path: "/pages/list/tpxw",
index:0,
}, {
title: "综合新闻",
src: "/static/images/zhxw.png",
path: "/pages/list/zhxw"
path: "/pages/list/zhxw",
index:1,
}, {
title: "市局通知",
src: "/static/images/sjtz.png",
path: "/pages/list/zhxw",
index:2,
}, {
title: "市局文件",
src: "/static/images/sjwj.png",
path: "/pages/list/zhxw",
index:3,
}, {
title: "各地警讯",
src: "/static/images/gdjx.png",
path: "/pages/list/gdjx"
path: "/pages/list/gdjx",
index:4,
}, {
title: "机关动态",
src: "/static/images/jgdt.png",
path: "/pages/list/jgdt"
path: "/pages/list/jgdt",
index:5,
}, {
title: "好警纪实",
src: "/static/images/hjjs.png",
path: "/pages/list/hjjs"
path: "/pages/list/hjjs",
index:6,
}, {
title: "警营文化",
src: "/static/images/jywh.png",
path: "pages/list/jywh"
path: "pages/list/jywh",
index:7,
}],
list:[{
title:"釉色渲染仕女图韵味被私藏,而你嫣然的一笑如含苞待放",
@ -130,18 +142,62 @@
}
},
onLoad() {
this.getList(7)
},
methods: {
changeItem(item) {
changeItem(item) {
// uni.redirectTo({
// url: '/pages/list/tpxw?menuindex='+item.index,
// });
// uni.setStorageSync("menuIndex", item.index);
uni.switchTab({
url: item.path,
url: '/pages/list/tpxw',
});
},
gocontent(){
uni.redirectTo({
url: '/pages/content/content',
});
},
getList(id){
console.log("aaa")
var that = this
// that.util.request({
// api: '',
// method: "GET",
// data: {
// action:"list",
// classid:id,
// page_size:1,
// page:1,
// ispic:1
// },
// utilSuccess: function(res) {
// // uni.showToast({
// // icon: "none",
// // title: "",
// // complete() {
// // that.afterSubmit(res);
// // },
// // duration: 2000
// // })
// },
// utilFail: function(res) {
// that.util.alert(res);
// }
// });
uni.request({
url: '?action=list&classid='+id+'&page_size=10&page=1&ispic=1',
method: "GET",
data: {
},
success: function(result) {
},
fail: function(res) {
// that.util.alert(res);
}
});
}
}
}

@ -19,15 +19,8 @@
<u-cell-item icon="clock-fill" title="浏览历史"></u-cell-item>
</u-cell-group>
</view>
</view>
<subtab-bar :currentPage="3"></subtab-bar>
<tab-bar :currentPage="3"></tab-bar>
</view>
</template>

@ -1,9 +1,19 @@
<template>
<top>
<view slot="content">
<menu-bar :tabs="list" :currentPage="0"></menu-bar>
<view slot="content" class="content">
<view class="swipers">
<u-swiper
:title="true"
border-radius="15"
duration="1500"
mode="dot"
height="300"
:list="imglist"></u-swiper>
</view>
<menu-bar :tabs="list" :currentPage="menuIndex"></menu-bar>
<subtab-bar :currentPage="2"></subtab-bar>
<tab-bar :currentPage="2"></tab-bar>
</view>
</top>
@ -11,8 +21,26 @@
<script>
export default {
onload(val){
console.log(val)
that.menuIndex = val.index
// location.reload()
},
onShow() {
var that = this
console.log('before',that.menuIndex)
that.menuIndex = uni.getStorageSync('menuIndex')?uni.getStorageSync('menuIndex'):0
console.log('after',that.menuIndex)
uni.removeStorageSync('menuIndex')
},
created() {
},
data() {
return {
menuIndex:0,
imglist: [
],
list:[[{
title:"于贵平主持召开第9次周调度例会",
times:"2022-08-21",
@ -45,7 +73,39 @@
title:"于贵平主持召开第9次周调度例会",
times:"2022-08-21",
imgs:"https://img11.360buyimg.com/n7/jfs/t1/94448/29/2734/524808/5dd4cc16E990dfb6b/59c256f85a8c3757.jpg",
}],[],[''],[''],[''],['']]
}],[{
title:"于贵平主持召开第9次周调度例会",
times:"2022-08-21",
imgs:"https://img11.360buyimg.com/n7/jfs/t1/94448/29/2734/524808/5dd4cc16E990dfb6b/59c256f85a8c3757.jpg",
},{
title:"于贵平主持召开第9次周调度例会",
times:"2022-08-21",
imgs:"https://img11.360buyimg.com/n7/jfs/t1/94448/29/2734/524808/5dd4cc16E990dfb6b/59c256f85a8c3757.jpg",
},{
title:"于贵平主持召开第9次周调度例会",
times:"2022-08-21",
imgs:"https://img11.360buyimg.com/n7/jfs/t1/94448/29/2734/524808/5dd4cc16E990dfb6b/59c256f85a8c3757.jpg",
},{
title:"于贵平主持召开第9次周调度例会",
times:"2022-08-21",
imgs:"https://img11.360buyimg.com/n7/jfs/t1/94448/29/2734/524808/5dd4cc16E990dfb6b/59c256f85a8c3757.jpg",
},{
title:"于贵平主持召开第9次周调度例会",
times:"2022-08-21",
imgs:"https://img11.360buyimg.com/n7/jfs/t1/94448/29/2734/524808/5dd4cc16E990dfb6b/59c256f85a8c3757.jpg",
},{
title:"于贵平主持召开第9次周调度例会",
times:"2022-08-21",
imgs:"https://img11.360buyimg.com/n7/jfs/t1/94448/29/2734/524808/5dd4cc16E990dfb6b/59c256f85a8c3757.jpg",
},{
title:"于贵平主持召开第9次周调度例会",
times:"2022-08-21",
imgs:"https://img11.360buyimg.com/n7/jfs/t1/94448/29/2734/524808/5dd4cc16E990dfb6b/59c256f85a8c3757.jpg",
},{
title:"于贵平主持召开第9次周调度例会",
times:"2022-08-21",
imgs:"https://img11.360buyimg.com/n7/jfs/t1/94448/29/2734/524808/5dd4cc16E990dfb6b/59c256f85a8c3757.jpg",
}],[],[''],[''],[''],[],[]]
}
},
methods: {
@ -55,6 +115,32 @@
</script>
<style scoped>
.swipers{
padding:40rpx;
padding-bottom:0
}
.content{
background-color: #fff;
}
.u-swiper-wrap{
height:360rpx
}
/deep/ .swipers .u-swiper-title{
padding-bottom: 10rpx !important;
}
/* /deep/ .u-swiper-indicator{
bottom: -40rpx !important;;
} */
/deep/ .u-indicator-item-dot{
background-color: #fff;
border: 1px solid #DB1B29;
width:20rpx;
height:20rpx;
}
/deep/ .u-indicator-item-dot-active{
background-color: #DB1B29;
}
</style>

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

@ -0,0 +1,559 @@
const HOSTARR = {
'development': 'http://czga.langye.net/e/extend/api/index.php',
// 'development': 'http://patrol.115.langye.net',
'production': 'http://czga.langye.net/e/extend/api/index.php'
}; // 审核状态
const HOST = HOSTARR[process.env
.NODE_ENV]; //"https://tiantianxinye.365care.langye.net/";//HOSTARR[process.env.NODE_ENV];//
const formatTime = date => {
const year = date.getFullYear();
const month = date.getMonth() + 1;
const day = date.getDate();
return [year, month, day].map(formatNumber).join('-');
};
const user_info_key = "userInfo_token";
const user_key = "userInfo";
const getUserInfo = (cb, refresh) => {
cb = cb || function() {}
refresh = refresh || false
if (!refresh) {
let user_info = uni.getStorageSync(user_key)
if (!isNull(user_info)) {
cb(user_info)
return
}
}
request({
api: '/api/mobile/user/show',
utilSuccess: function(res) {
uni.setStorageSync(user_key, res)
cb(res)
},
utilFail: function(res) {}
})
}
const getOpenidInfo = (cb, refresh) => {
cb = cb || function() {}
refresh = refresh || false
if (!refresh) {
let user_info = uni.getStorageSync(user_info_key)
if (!isNull(user_info)) {
cb(user_info)
return
}
}
uni.login({
provider: 'weixin',
success: (res) => {
console.log(res.code);
let url = HOST + '/api/mobile/user/login?code=' + res.code;
uni.request({
url: url,
method: 'GET',
success: result => {
let user_info = result.data
uni.setStorageSync(user_info_key, user_info)
cb(user_info)
}
});
}
});
}
const getUserProfile = (cb) => {
cb = cb || function() {}
wx.getUserProfile({
desc: '用于完善会员资料',
success: (res) => {
uni.setStorageSync('user_profile', res.userInfo)
cb(res.userInfo)
}
})
}
const formatTimeAll = date => {
const year = date.getFullYear();
const month = date.getMonth() + 1;
const day = date.getDate();
const hour = date.getHours();
const minute = date.getMinutes();
const second = date.getSeconds();
return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(
':');
};
const formatNumber = n => {
n = n.toString();
return n[1] ? n : '0' + n;
}; // 快捷显示alert
const alert = msg => {
uni.showModal({
title: '',
content: msg,
showCancel: false
});
}; // 订单状态
const toast = msg => {
// setTimeout(function() {
// uni.showToast({
// icon: "none",
// title: msg,
// duration: 2000
// })
// }, 2000)
uni.showModal({
title: '',
content: msg,
showCancel: false
});
}; // 订单状态
const orderStatusDic = {
'0': '待确认',
'10': '待派单',
'20': '进行中',
'100': '已完成'
}; // 审核状态
const auditStatusDic = {
'0': '待审核',
'1': '已审核',
'-1': '已拒绝'
}; // 请求封装
const request = options => {
if (!options.customLoading) {
uni.showLoading({
title: '正在加载'
});
} else {
// 当前页面请求数量+1
if (options.bindThis) {
options.bindThis.setData({
//loadingCount: options.bindThis.data.loadingCount + 1
});
}
}
options.url = HOST + options.api;
options.header = {
...options.header,
//'Accept': 'application/json',
//'Connection': 'keep-alive'
//'content-type': 'application/json'
}; // 如果已登录,请求中拼openId
// var access_token = uni.getStorageSync(user_info_key).access_token;
if (isLogin()) {
options.data = {
...options.data,
// 'token': access_token
};
} // 如果是POST方法
// if (options.method == 'POST' && !isNull(access_token)) {
// // 拼时间戳
// options.data.ts = new Date().getTime();
// }
uni.request({
...options,
success: function(res) {
uni.hideLoading();
if (res.statusCode != 200) {
if (options.utilFail != undefined) {
if (res.statusCode == 401) {
uni.clearStorageSync();
uni.navigateTo({
url: '/pages/login/login'
});
} else {
options.utilFail('TODO: 特殊处理非200错误(' + res.statusCode + ')');
}
}
} else {
if (res.data.hasOwnProperty("errcode")) {
if (options.utilFail != undefined) {
options.utilFail(res.data.errmsg || '接口发生未知错误');
} else {
options.utilFail(res.data.errmsg);
}
} else {
if (options.utilSuccess != undefined) {
options.utilSuccess(res.data);
}
}
}
},
fail: options.utilFail,
complete: function(res) {
if (!options.customLoading) {
uni.hideNavigationBarLoading();
} else {
// 当前页面请求数量-1
if (options.bindThis) {
options.bindThis.setData({
loadingCount: options.bindThis.data.loadingCount - 1
});
}
}
}
});
}; // 提交formID封装
const payOrder = (orderID, orderType, success, fail) => {
uni.request({
url: HOST + 'WxPay/ToPay?openId=' + uni.getStorageSync(user_info_key).WeChatOpenID +
'&orderId=' +
orderID + '&OrderType=' + orderType,
method: 'GET',
header: {
'content-type': 'application/json'
},
success: function(res) {
// 内容为空, 代表失败
if (res.data == '') {
fail('当前网络状况不好');
return;
} // 去掉转义字符
var pureStr = res.data.replace(/\\/g, '');
res.data = JSON.parse(pureStr);
var index = res.data.package.indexOf('=') + 1;
var prepayId = res.data.package.substring(index); // wxpay
uni.requestPayment({
timeStamp: res.data.timeStamp,
nonceStr: res.data.nonceStr,
package: res.data.package,
signType: res.data.signType,
paySign: res.data.paySign,
success: function(res) {
success(res); // 发送成功通知
request({
api: 'WxPay/PayTemplateMsg',
data: {
prepay_id: prepayId,
orderId: orderID,
isSuccess: 1,
failMsg: '',
xType: orderType
}
});
},
fail: function(res) {
fail(res);
var errMsg = res == 'requestPayment:fail cancel' ? '用户取消支付' :
res; // 发送失败通知
request({
api: 'WxPay/PayTemplateMsg',
data: {
prepay_id: prepayId,
orderId: orderID,
isSuccess: 0,
failMsg: errMsg,
xType: orderType
}
});
}
});
},
fail: function(err) {
fail('当前网络状况不好');
}
});
}; // 判断是否已登录同时有open-id和PhoneNum, 则认为已登录)
const isLogin = () => {
// var userInfo = uni.getStorageSync(user_info_key);
// return !isNull(userInfo.access_token);
}; // 判断是否为空
const isNull = p => {
return p == '' || p == undefined || p == null || p == 'undefined' || p == 'null';
}; // 正则
const phoneRegex = /^1\d{10}$/;
const idCardRegex = /^\d{17}([0-9]|X)$/; // 去掉特殊字符
const filterSpecialChars = str => {
return str.replace(/[^\u4e00-\u9fa5a-zA-Z0-9\w]/g, '');
}; // 生成随机字符串
const randomStr = length => {
var ret = '';
var arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C',
'D', 'E',
'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z'
];
for (var i = 0; i < length; i++) {
var randomIndex = Math.round(Math.random() * (arr.length - 1));
ret += arr[randomIndex];
}
return ret;
}; // proType对应的中文描述
const weekdayArr = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']; // 是否合法的身份证
const isValidCardID = cardID => {
// Step1: 先判断格式
if (!idCardRegex.test(cardID)) return false; // Step2: 校验最后一位
var code = cardID.split(''); //加权因子
var factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]; //校验位
var parity = [1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2];
var sum = 0;
var ai = 0;
var wi = 0;
for (var i = 0; i < 17; i++) {
ai = code[i];
wi = factor[i];
sum += ai * wi;
}
var last = parity[sum % 11];
return parity[sum % 11] == code[17];
};
/**
* UTF16和UTF8转换对照表
* U+00000000 U+0000007F 0xxxxxxx
* U+00000080 U+000007FF 110xxxxx 10xxxxxx
* U+00000800 U+0000FFFF 1110xxxx 10xxxxxx 10xxxxxx
* U+00010000 U+001FFFFF 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
* U+00200000 U+03FFFFFF 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
* U+04000000 U+7FFFFFFF 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
*/
var Base64 = {
// 转码表
table: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
'T', 'U',
'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p',
'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8',
'9', '+',
'/'
],
UTF16ToUTF8: function(str) {
var res = [],
len = str.length;
for (var i = 0; i < len; i++) {
var code = str.charCodeAt(i);
if (code > 0x0000 && code <= 0x007F) {
// 单字节这里并不考虑0x0000因为它是空字节
// U+00000000 U+0000007F 0xxxxxxx
res.push(str.charAt(i));
} else if (code >= 0x0080 && code <= 0x07FF) {
// 双字节
// U+00000080 U+000007FF 110xxxxx 10xxxxxx
// 110xxxxx
var byte1 = 0xC0 | code >> 6 & 0x1F; // 10xxxxxx
var byte2 = 0x80 | code & 0x3F;
res.push(String.fromCharCode(byte1), String.fromCharCode(byte2));
} else if (code >= 0x0800 && code <= 0xFFFF) {
// 三字节
// U+00000800 U+0000FFFF 1110xxxx 10xxxxxx 10xxxxxx
// 1110xxxx
var byte1 = 0xE0 | code >> 12 & 0x0F; // 10xxxxxx
var byte2 = 0x80 | code >> 6 & 0x3F; // 10xxxxxx
var byte3 = 0x80 | code & 0x3F;
res.push(String.fromCharCode(byte1), String.fromCharCode(byte2), String.fromCharCode(
byte3));
} else if (code >= 0x00010000 && code <= 0x001FFFFF) { // 四字节
// U+00010000 U+001FFFFF 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
} else if (code >= 0x00200000 && code <= 0x03FFFFFF) { // 五字节
// U+00200000 U+03FFFFFF 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
} else
/** if (code >= 0x04000000 && code <= 0x7FFFFFFF)*/
{ // 六字节
// U+04000000 U+7FFFFFFF 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
}
}
return res.join('');
},
UTF8ToUTF16: function(str) {
var res = [],
len = str.length;
var i = 0;
for (var i = 0; i < len; i++) {
var code = str.charCodeAt(i); // 对第一个字节进行判断
if ((code >> 7 & 0xFF) == 0x0) {
// 单字节
// 0xxxxxxx
res.push(str.charAt(i));
} else if ((code >> 5 & 0xFF) == 0x6) {
// 双字节
// 110xxxxx 10xxxxxx
var code2 = str.charCodeAt(++i);
var byte1 = (code & 0x1F) << 6;
var byte2 = code2 & 0x3F;
var utf16 = byte1 | byte2;
res.push(Sting.fromCharCode(utf16));
} else if ((code >> 4 & 0xFF) == 0xE) {
// 三字节
// 1110xxxx 10xxxxxx 10xxxxxx
var code2 = str.charCodeAt(++i);
var code3 = str.charCodeAt(++i);
var byte1 = code << 4 | code2 >> 2 & 0x0F;
var byte2 = (code2 & 0x03) << 6 | code3 & 0x3F;
utf16 = (byte1 & 0x00FF) << 8 | byte2;
res.push(String.fromCharCode(utf16));
} else if ((code >> 3 & 0xFF) == 0x1E) { // 四字节
// 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
} else if ((code >> 2 & 0xFF) == 0x3E) { // 五字节
// 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
} else
/** if (((code >> 1) & 0xFF) == 0x7E)*/
{ // 六字节
// 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
}
}
return res.join('');
},
encode: function(str) {
if (!str) {
return '';
}
var utf8 = this.UTF16ToUTF8(str); // 转成UTF8
var i = 0; // 遍历索引
var len = utf8.length;
var res = [];
while (i < len) {
var c1 = utf8.charCodeAt(i++) & 0xFF;
res.push(this.table[c1 >> 2]); // 需要补2个=
if (i == len) {
res.push(this.table[(c1 & 0x3) << 4]);
res.push('==');
break;
}
var c2 = utf8.charCodeAt(i++); // 需要补1个=
if (i == len) {
res.push(this.table[(c1 & 0x3) << 4 | c2 >> 4 & 0x0F]);
res.push(this.table[(c2 & 0x0F) << 2]);
res.push('=');
break;
}
var c3 = utf8.charCodeAt(i++);
res.push(this.table[(c1 & 0x3) << 4 | c2 >> 4 & 0x0F]);
res.push(this.table[(c2 & 0x0F) << 2 | (c3 & 0xC0) >> 6]);
res.push(this.table[c3 & 0x3F]);
}
return res.join('');
},
decode: function(str) {
if (!str) {
return '';
}
var len = str.length;
var i = 0;
var res = [];
while (i < len) {
var code1 = this.table.indexOf(str.charAt(i++));
var code2 = this.table.indexOf(str.charAt(i++));
var code3 = this.table.indexOf(str.charAt(i++));
var code4 = this.table.indexOf(str.charAt(i++));
var c1 = code1 << 2 | code2 >> 4;
var c2 = (code2 & 0xF) << 4 | code3 >> 2;
var c3 = (code3 & 0x3) << 6 | code4;
res.push(String.fromCharCode(c1));
if (code3 != 64) {
res.push(String.fromCharCode(c2));
}
if (code4 != 64) {
res.push(String.fromCharCode(c3));
}
}
return this.UTF8ToUTF16(res.join(''));
}
};
module.exports = {
HOST: HOST,
formatTime: formatTime,
formatTimeAll: formatTimeAll,
formatNumber: formatNumber,
alert: alert,
getOpenidInfo: getOpenidInfo,
request: request,
payOrder: payOrder,
isLogin: isLogin,
isNull: isNull,
phoneRegex: phoneRegex,
idCardRegex: idCardRegex,
filterSpecialChars: filterSpecialChars,
randomStr: randomStr,
weekdayArr: weekdayArr,
Base64: Base64,
orderStatusDic: orderStatusDic,
auditStatusDic: auditStatusDic,
getUserProfile: getUserProfile,
getUserInfo: getUserInfo,
toast: toast,
isValidCardID:isValidCardID,
};
Loading…
Cancel
Save