学习uni-app记录
生活随笔
收集整理的這篇文章主要介紹了
学习uni-app记录
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
小程序page.json全局配置
{"pages": [ //pages數(shù)組中第一項表示應(yīng)用啟動頁,參考:https://uniapp.dcloud.io/collocation/pages{"path": "pages/workbench/workbench","style": {// "navigationBarTitleText": "工作臺", //下面的buttons內(nèi)容會將其覆蓋"app-plus": { //App端擴展配置"titleNView": { //原生導(dǎo)航欄配置參數(shù)"autoBackButton": true,"buttons": [ //原生標(biāo)題欄按鈕配置,點擊事件可通過頁面的 onNavigationBarButtonTap 函數(shù)進行監(jiān)聽。如:top導(dǎo)航欄后退按鈕。然后在pages/workbench/workbench點擊事件(與data和onload同級):{"type": "none", // 需通過 text 屬性設(shè)置按鈕上顯示的內(nèi)容、通過 fontSrc 屬性設(shè)置使用的字體庫。"text": "數(shù)字婺城","float": "left","id": "test1","fontSize":"16px" //標(biāo)題的字體大小},{"type": "back", // 使用 type 值設(shè)置按鈕的樣式時,會忽略 fontSrc 和 text 屬性。"float": "left","id": "test0"}],"searchInput": { // 在vue/nvue頁面中可通過onNavigationBarSearchInputChanged事件監(jiān)聽搜索框輸入內(nèi)容變化"autoFocus": true,// "borderRadius": "10upx","borderRadius": "6px", //輸入框圓角"backgroundColor": "#F5F4F4","placeholder": "請輸入搜索內(nèi)容"// "disabled": true //disable時點擊輸入框不置焦,可以跳到新頁面搜索 }}}}},{"path": "pages/login/login",// "style": {// "navigationBarTitleText": "數(shù)字婺城",// "enablePullDownRefresh": false// }"style": {"navigationBarTitleText": "數(shù)字婺城","app-plus": { //App端擴展配置"scrollIndicator": "none","titleNView": { //原生導(dǎo)航欄配置參數(shù)"homeButton": true,"autoBackButton": true, // false,取消pages頁面的默認(rèn)返回按鈕。自定義返回按鈕的樣式// 當(dāng)autoBackButton設(shè)置為true時生效。 通過如下button中的type屬性可自定義返回按鈕樣式,如圖標(biāo)大小、紅點、角標(biāo)、標(biāo)題等。"buttons": [ //原生標(biāo)題欄按鈕配置,{"type": "home", // 使用 type 值設(shè)置按鈕的樣式時,會忽略 fontSrc 和 text 屬性。"float": "left","id": "test0"}// {// "type": "none",// "text": "自定義",// "float": "right",// "id": "test1"// },// {// "type": "none",// "text": "\u2708",// "float": "right",// "id": "test2"// }]// "buttons": [{ //原生標(biāo)題欄按鈕配置,// "type": "none",// "text": "\u2716",// "float": "left",// "fontSrc": "/static/uni.ttf",// "fontSize": "22px"// }]// 原生導(dǎo)航欄自定義按鈕帶紅點和角標(biāo)// ,"buttons": [{// "text": "消息",// "fontSize": "14",// "redDot": true// },// {// "text": "關(guān)注",// "fontSize": "14",// "badgeText": "12"// }// ]// 原生導(dǎo)航欄自定義按鈕帶下拉選擇(城市選擇)// "buttons": [{// "text": "北京市",// "fontSize": "14",// "select": true,// "width": "auto"// }]// 帶搜索// "searchInput": {// "autoFocus": true,// // "borderRadius": "10upx",// "borderRadius": "6px", //輸入框圓角// "backgroundColor": "#F5F4F4",// "placeholder": "請輸入搜索內(nèi)容"// // "disabled": true //disable時點擊輸入框不置焦,可以跳到新頁面搜索// }// "type": "transparent", //配置原生導(dǎo)航欄的透明漸變:頁面剛載入時沒有導(dǎo)航標(biāo)題,頁面內(nèi)容通頂?shù)綘顟B(tài)欄里,頁面向下滾動后標(biāo)題欄漸變出現(xiàn)。// "bounce": "none", //關(guān)閉窗口回彈效果// "backgroundImage": "/static/logo.png", //設(shè)置背景圖 }}}},{"path": "pages/index/index","style": {"navigationBarTitleText": "uni-app"}}],"globalStyle": { // 全局導(dǎo)航欄樣式設(shè)置"navigationBarBackgroundColor": "#007AFF", // 導(dǎo)航欄背景顏色(同狀態(tài)欄背景色)"navigationBarTextStyle": "white", // 導(dǎo)航欄標(biāo)題顏色及狀態(tài)欄前景顏色,僅支持 black/white"navigationBarTitleText": "數(shù)字婺城", // 導(dǎo)航欄標(biāo)題文字內(nèi)容"backgroundColor": "#F8F8F8"},"tabBar": {"color": "#aeafb1", // 表示tabBar item項中文字默認(rèn)的顏色"selectedColor": "#004de8", // 表示tabBar item項中文字選中的顏色"borderStyle": "black", // 表示tabBar 上邊框的顏色,目前只支持 black/white"backgroundColor": "#ffffff", // 表示 tabBar 的背景顏色"height": "80px", // tabbar的高"fontSize": "16px", // 文字大小"iconWidth": "35px", // 圖標(biāo)寬帶"spacing": "3px", // 圖標(biāo)和文字之間的間距"list": [{"pagePath": "pages/information/information", // 表示第一tab項的頁面路徑"iconPath": "static/logo.png", // 表示當(dāng)前 tab 未選中時所顯示的圖標(biāo)路徑"selectedIconPath": "static/logo.png", // 表示當(dāng)前 tab 選中時所顯示的圖標(biāo)文件路徑"text": "消息" //菜單文字},{"pagePath": "pages/login/login","iconPath": "static/logo.png","selectedIconPath": "static/logo.png","text": "待辦"},{"pagePath": "pages/workbench/workbench","iconPath": "static/logo.png","selectedIconPath": "static/logo.png","text": "工作臺"},{"pagePath": "pages/addressBook/addressBook","iconPath": "static/logo.png","selectedIconPath": "static/logo.png","text": "通訊錄"},{"pagePath": "pages/mine/mine","iconPath": "static/logo.png","selectedIconPath": "static/logo.png","text": "我的"}]} }某個頁面
<template><view>hi,{{this.$store.state.inputSearchValue}}<view class="indeximg"><!-- <canvas class="relative" :style="{width: fullHeight}" canvas-id="firstCanvas"></canvas> --><!-- <canvas style="width: 99.8%;height: 450px; border: solid 1rpx #aaaaff; " canvas-id="firstCanvas"></canvas> --><canvas class="relative" :style="{height:this.$store.state.fullHeight+'px',width:this.$store.state.fullWidth+'px',border: '1px red solid'}" canvas-id="firstCanvas">{{this.$store.state.fullHeight}}{{this.$store.state.fullWidth}}</canvas></view></view> </template><script>export default {data() {return {};},// onShow() {// uni.getSystemInfo({// success: function (res) {// console.log("屏幕寬度:"+res.screenWidth);// console.log("屏幕高度:"+res.screenHeight);// console.log("可使用窗口寬度:"+res.windowWidth);// console.log("可使用窗口高度:"+res.windowHeight);// }// });// },methods:{back() { //top導(dǎo)航欄 后退轉(zhuǎn)跳頁面uni.switchTab({ // 代碼跳轉(zhuǎn)到 tabbar 頁面,api只能使用uni.switchTab,不能使用uni.navigateTo、uni.redirectTo;使用navigator組件跳轉(zhuǎn)時必須設(shè)置open-type="switchTab"url: "/pages/login/login"})},cavansChange(){}},mounted() {const that = this;let newHeight = '';let newWidth = '';uni.getSystemInfo({success: function (res) {console.log('res',res)let newHeight = that.fullHeight ="height:" + res.windowHeight + "px";let newWidth = that.fullWidth ="Width:" + res.windowWidth + "px";newHeight = newHeight;newWidth = newWidth;console.log('---------------newHeight',newHeight);console.log('---------------newWidth',newWidth);that.$store.commit('getHeight',newHeight);that.$store.commit('getWidth',newWidth);}});},onNavigationBarButtonTap(e) { // 監(jiān)聽原生標(biāo)題欄按鈕點擊事件,參數(shù)為Object; //top導(dǎo)航欄 后退按鈕事件console.log("success") this.back();},onNavigationBarSearchInputChanged(e) { //監(jiān)聽原生標(biāo)題欄搜索輸入框輸入內(nèi)容變化事件; //top導(dǎo)航欄 inputSearch按鈕事件let text = e.text; // 為搜索框中輸入的內(nèi)容// console.log(text)// this.$store.commit('changeInputSearchValue', text);this.$store.dispatch('getInputSearchValue', text);}} </script><style lang="stylus"></style>store/index.js
import Vue from 'vue' import Vuex from 'vuex'Vue.use(Vuex)export default new Vuex.Store({state: {get UserToken() {return JSON.parse(sessionStorage.getItem('UserToken'));},set UserToken(UserToken) {if (UserToken) {return sessionStorage.setItem('UserToken', JSON.stringify(UserToken))} else {return sessionStorage.removeItem('UserToken')}},userInfo: "yy", // yhr testtitle: 'input--yhr',inputValue: '',userInfos:{username:'AAA',password:'BBB'},inputSearchValue:'',fullHeight:'', //畫布屏幕高度fullWidth:'', //畫布屏幕寬度},getters:{//相當(dāng)于computedgetHeight(state){return state.fullHeight;},},mutations: { //相當(dāng)于methodsLOGIN_IN(state, UserToken) {state.UserToken = UserToken;},LOGIN_OUT(state) {state.UserToken = null;},changeInfo(state, newName) {// console.log('state,newName', state, newName);state.userInfo = newName},changeTitle(state, newtitle) {// console.log('state,newtitle', state, newtitle);state.title = newtitle},changeInputSearchValue(state, newValue){ //工作臺,top導(dǎo)航 搜索欄// console.log('state,newValue', state, newValue);state.inputSearchValue = newValue},// 設(shè)置畫布高寬getHeight(state, newHeight){state.fullHeight = newHeightconsole.log('state.fullHeight', state.fullHeight);},// getWidth(state, newWidth){state.fullWidth = newWidthconsole.log('state.fullWidth', state.fullWidth);}// 獲取用戶信息// getUserInfo(state,UserInfo){// state.userInfos.username = UserInfo.username// state.userInfos.password = UserInfo.password// }},// 修改state中的全局?jǐn)?shù)據(jù)的間接接口,可以為異步函數(shù),通過調(diào)用mutations中的函數(shù)實現(xiàn)對state的修改actions: { // 使用actions,通過mutations更改state的值getNewName(context, data) { //同上注釋,data為要變化的形參context.commit('changeInfo', data)},// 或:用到context對象的commit屬性// getNewName({// commit// }, data) {// commit('changeInfo', data)// }getInputSearchValue(context, data){context.commit('changeInputSearchValue', data)}} })utils/config.js
import store from '@/store/index' //項目域名地址 let baseUrl; let orginUrl; if (process.env.NODE_ENV === "development") { //開發(fā)環(huán)境下的地址// orginUrl = "http://192.168.1.189:9001";// orginUrl = "http://192.168.1.168:8881";// baseUrl = orginUrl;orginUrl = "https://dfov-intyyte-ayl.yy.gov.cn/mhypi";baseUrl = orginUrl;} else { //生產(chǎn)環(huán)境下的地址orginUrl = 'https://dffov-ifffate.ffch.gov.cn/api/';baseUrl = orginUrl; }export { baseUrl }; export { orginUrl };utils/pucblic.js
/*** 校驗空*/ export function isEmptyValue(val) {if (val == '' || val == null || val == undefined) {return true;}return false }/*** 校驗空并返回提示信息*/ export function isEmptyValueTips(val, msg) {if (isEmptyValue(val)) {showToastMsg(msg);return true;}return false; }/*** 校驗空并返回制定的格式*/ export function isEmptyValueFormat(val, fmt) {if (isEmptyValue(val)) {return fmt;}return val; }/*** 提示信息*/ export function showToastMsg(msg) {uni.showToast({icon: 'none',title: msg,}); }/*** 獲取url指定的參數(shù)* @param {Object} name*/ export function getUrlParam(name) {var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //構(gòu)造一個含有目標(biāo)參數(shù)的正則表達式對象var r = window.location.search.substr(1).match(reg); //匹配目標(biāo)參數(shù)if (r != null) return decodeURI(r[2]);return null; //返回參數(shù)值 }/*** 獲取當(dāng)前日期及后 num -1 天 共num天* @param {Object} num*/ export function funDate(num){ let weeks = ['星期日','星期一','星期二','星期三','星期四','星期五','星期六'];let dateList = new Array();let date = new Date();date.setDate(date.getDate());for(let i=0;i<num;i++){let year = date.getFullYear();let month = (date.getMonth()+1)>=10?date.getMonth()+1:'0'+(date.getMonth()+1);let day = date.getDate()>=10?date.getDate():'0'+date.getDate();let dateTemp = year+'-'+month+'-'+day;let weekTemp = weeks[date.getDay()];let obj = {label: dateTemp+' '+weekTemp,value: dateTemp}dateList.push(obj);date.setDate(date.getDate() + 1);}return dateList; }/*** 時間格式話*/ export function FormatDate2(date) {date = new Date(date);var o = {year:date.getFullYear(),month: date.getMonth() + 1, //月份 day: date.getDate(), //日 hour: date.getHours(), //小時 minutes: date.getMinutes(), //分 quarter: Math.floor((date.getMonth() + 3) / 3), //季度 };return o; } export function FormatDate(date, fmt) {//處理iphone系統(tǒng)小程序不支持2020-01-01格式時間的格式化問題// date = date.replace(/-/g, "/");date = new Date(date);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() //毫秒 };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) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));return fmt; } /*** 計算兩個經(jīng)緯度之間的距離*/ export function getDistance(latFrom, lngFrom, latTo, lngTo) {latFrom = latFrom || 0;lngFrom = lngFrom || 0;latTo = latTo || 0;lngTo = lngTo || 0;var radLatFrom = latFrom * Math.PI / 180.0;var radLatTo = latTo * Math.PI / 180.0;var a = radLatFrom - radLatTo;var b = lngFrom * Math.PI / 180.0 - lngTo * Math.PI / 180.0;var distance = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLatFrom) * Math.cos(radLatTo) * Math.pow(Math.sin(b / 2), 2)));distance = distance * 6378136.49;distance = Math.round(distance * 10000) / 10000;return parseFloat(distance.toFixed(0)) }/*** 判斷經(jīng)緯度是否超出中國境內(nèi)*/ export function isLocationOutOfChina(latitude, longitude) {if (longitude < 72.004 || longitude > 137.8347 || latitude < 0.8293 || latitude > 55.8271)return true;return false; }/*** 將百度坐標(biāo)轉(zhuǎn)為GCJ-02(火星坐標(biāo)):*/ export function transformFromBaiduToGCJ(latitude, longitude) {var xPi = 3.14159265358979323846264338327950288 * 3000.0 / 180.0;var x = longitude - 0.0065;var y = latitude - 0.006;var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * xPi);var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * xPi);var a_latitude = z * Math.sin(theta);var a_longitude = z * Math.cos(theta);return { latitude: a_latitude, longitude: a_longitude }; }/*** 將GCJ-02(火星坐標(biāo))轉(zhuǎn)為百度坐標(biāo):*/ export function transformFromGCJToBaidu(latitude, longitude) { var pi = 3.14159265358979324 * 3000.0 / 180.0;var z = Math.sqrt(longitude * longitude + latitude * latitude) + 0.00002 * Math.sin(latitude * pi);var theta = Math.atan2(latitude, longitude) + 0.000003 * Math.cos(longitude * pi);var a_latitude = (z * Math.sin(theta) + 0.006);var a_longitude = (z * Math.cos(theta) + 0.0065);return { latitude: a_latitude, longitude: a_longitude }; }/*** 將WGS-84(國際標(biāo)準(zhǔn))轉(zhuǎn)為GCJ-02(火星坐標(biāo)):*/ export function transformFromWGSToGCJ(latitude, longitude) {var lat = "";var lon = "";var ee = 0.00669342162296594323;var a = 6378245.0;var pi = 3.14159265358979324;if (isLocationOutOfChina(latitude, longitude)) {lat = latitude;lon = longitude;} else {var adjustLat = transformLatWithXY(longitude - 105.0, latitude - 35.0);var adjustLon = transformLonWithXY(longitude - 105.0, latitude - 35.0);var radLat = latitude / 180.0 * pi;var magic = Math.sin(radLat);magic = 1 - ee * magic * magic;var sqrtMagic = Math.sqrt(magic);adjustLat = (adjustLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi);adjustLon = (adjustLon * 180.0) / (a / sqrtMagic * Math.cos(radLat) * pi);latitude = latitude + adjustLat;longitude = longitude + adjustLon;}return {latitude: latitude,longitude: longitude};}export function transformLatWithXY(x, y) {var pi = 3.14159265358979324;var lat = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x));lat += (20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0 / 3.0;lat += (20.0 * Math.sin(y * pi) + 40.0 * Math.sin(y / 3.0 * pi)) * 2.0 / 3.0;lat += (160.0 * Math.sin(y / 12.0 * pi) + 320 * Math.sin(y * pi / 30.0)) * 2.0 / 3.0;return lat; }export function transformLonWithXY(x, y) {var pi = 3.14159265358979324;var lon = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x));lon += (20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0 / 3.0;lon += (20.0 * Math.sin(x * pi) + 40.0 * Math.sin(x / 3.0 * pi)) * 2.0 / 3.0;lon += (150.0 * Math.sin(x / 12.0 * pi) + 300.0 * Math.sin(x / 30.0 * pi)) * 2.0 / 3.0;return lon; }//時間格式轉(zhuǎn)換 export function timeFormat(time) {let date = time.split('-')let year = date[0]let month = date[1].replace(/\b(0+)/gi,"")return year+'年'+month+'月'} //浙里辦頁面埋點 export function zlbMaData(){const sUserAgent = window.navigator.userAgent.toLowerCase();const bIsDtDreamApp = sUserAgent.indexOf("dtdreamweb") > -1; // 浙里辦APPconst bIsAlipayMini = sUserAgent.indexOf("alipay") > -1; //支付寶let longLat = JSON.parse(sessionStorage.getItem('longLat'))let userType = sessionStorage.getItem('userType')if(bIsDtDreamApp){if(longLat && userType){// 單頁應(yīng)用 或 “單個頁面”需異步補充 PV 日志參數(shù)還需進行如下埋點:aplus_queue.push({ action: 'aplus.setMetaInfo', arguments: ['aplus-waiting', 'MAN'] }); // 單頁應(yīng)用路由切換后 或 在異步獲取到 pv 日志所需的參數(shù)后再執(zhí)行 sendPV:aplus_queue.push({ 'action':'aplus.sendPV', 'arguments':[{ is_auto: false }, {miniAppId:'2001836403'},{miniAppName:'永康民情通'},{long:longLat.longitude},{lat:longLat.latitude},{userType:userType}] })}} }utils/request.js
/*** 網(wǎng)絡(luò)請求*/ import {isEmptyValue, showToastMsg} from './public.js'; import { baseUrl } from './config'; import store from '@/store/index'export function request (options) {return new Promise((resolve, reject) => {//獲取登錄用戶信息let UserToken = store.state.UserToken;// 獲取tokenlet token = '';if(!isEmptyValue(UserToken)){token = UserToken;}//設(shè)置請求headerlet header = {appCode: 'SZJH',Accept: 'application/json',token: token,}//遮罩uni.showLoading({title: '加載中……',mask: true //是否顯示透明蒙層,防止觸摸穿透,默認(rèn): false})let method = options.method == 'GET'?'GET':'POST';let data = isEmptyValue(options.data)? '': options.data;uni.request({url: baseUrl + options.url,method: method,data: data,timeout: 30000,withCredentials: true,header: header,success: (res) => {uni.showModal({title: '提示11111',content: JSON.stringify(res),success: function (res) {if (res.confirm) {console.log('用戶點擊確定');} else if (res.cancel) {console.log('用戶點擊取消');}}});let code = res.data.code;let msg = res.data.msg;if(code == '200'){resolve(res.data);}else if(code == '403'){uni.reLaunch({url: '/pages/login/login'})}else{showToastMsg(res.data.msg);}},fail: (err) => {uni.showModal({title: '提示22222',content: JSON.stringify(err),success: function (res) {if (res.confirm) {console.log('用戶點擊確定');} else if (res.cancel) {console.log('用戶點擊取消');}}});reject(err);showToastMsg(err);},complete: () => {uni.hideLoading();}})}) }總結(jié)
以上是生活随笔為你收集整理的学习uni-app记录的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Ubuntu下C语言程序的编写
- 下一篇: vue面试核心,双向数据绑定,数据代理,