實習第十一周,第十二周

繼續(xù)

1. 瀏覽器通知

    if(window.Notification && Notification.permission !== "denied") {
        Notification.requestPermission(function(status) {
           var n = new Notification('通知標題', { body: '這里是通知內(nèi)容!'}); 
        }); 
    } 

判斷用戶是否授權通知

    Notification.requestPermission(function (status) {
      if (status === "granted") {
        var n = new Notification("Hi!");
      } else {
        alert("Hi!");
      }

Notification對象作為構(gòu)造函數(shù)使用時,用來生成一條通知。

var notification = new Notification(title, options);

title屬性是必須的,用來指定通知的標題,格式為字符串。options屬性是可選的,格式為一個對象,用來設定各種設置

  • dir:文字方向,可能的值為auto、ltr(從左到右)和rtl(從右到左),一般是繼承瀏覽器的設置。
  • lang:使用的語種,比如en-US、zh-CN。
  • body:通知內(nèi)容,格式為字符串,用來進一步說明通知的目的。。
  • tag:通知的ID,格式為字符串。一組相同tag的通知,不會同時顯示,只會在用戶關閉前一個通知后,在原位置顯示。
  • icon:圖表的URL,用來顯示在通知上。

2.js判斷字符串為空

    if(a !== undefined && a !== null && a !== ""){
      console.log("字符串不為空")
    } else{
      console.log("字符串為空")
    }

3.nginx防止域名被其他ip解析

    server {
      listen 80 default;
      return 500;
    }  

4.git操作歷史記錄

https://www.centos.bz/2017/09/reset-git-history/

5.數(shù)組去重

[...new Set([arr])]

6.js復制input中的數(shù)據(jù)

    document.querySelector("").select()//選取input中數(shù)據(jù)
    document.execCommand("copy")//復制到粘貼版
    <input type="text" id="input" value="text disabled test" readonly>
    <button id="btn">copy</button>
    <script>
            var theInput = document.getElementById("input")
            var btn = document.getElementById("btn")
            btn.onclick = function() {
                document.querySelector("#input").select()
                document.execCommand("copy")
            }
    </script>

7.js生成隨機顏色

    function bg1(){
      return '#'+Math.floor(Math.random()*256).toString(10);
    }
    function bg2(){
      return '#'+Math.floor(Math.random()*0xffffff).toString(16);
    }
    function bg3(){
      var r=Math.floor(Math.random()*256);
      var g=Math.floor(Math.random()*256);
      var b=Math.floor(Math.random()*256);
      return "rgb("+r+','+g+','+b+")";//所有方法的拼接都可以用ES6新特性`其他字符串{$變量名}`替換
    }

8.express跨域

    app.all('*',function(req,res,next){
            res.header("Access-Control-Allow-Origin","*");
            res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
            res.header("Access-Control-Allow-Methods","*");
            next();
    })

9.express解析post的數(shù)據(jù)

    app.use(bodyParser.json());
    app.use(bodyParser.urlencoded({ extended: false }));
    app.post('/msgtime',function(req,res){
         console.log(req.body)
         res.send('{"statusCode":200}')
    })

10.ng彈框提示插件

https://github.com/Foxandxss/angular-toastr

angular.module('app', ['ngAnimate', 'toastr'])

11.promise練習

    var  p = new Promise(function(resolve,reject){
      console.log("starting...")
      var arr = '{"name":"klren","age":23}'
      resolve(arr)
    })
    p.then(function(resolve,reject){
      console.log(JSON.parse(resolve))
    })
    .then(function(resolve, reject){
      console.log("third")
    })
    var p1 = new Promise(function(resolve, reject){
      setTimeout(resolve, 500, 'P1');
    });
    var p2 = new Promise(function(resolve, reject){
      setTimeout(resolve, 600, 'P2');
    });
    //都執(zhí)行,按數(shù)組先后順序
    Promise.all([p2, p1]).then(function(result){
      console.log(result);
    })
    //誰先執(zhí)行就先執(zhí)行誰,第一個執(zhí)行完后,其他無法執(zhí)行
    Promise.race([p2, p1]).then(function(result){
      console.log(result);
    })

12.mysql將表中的時間戳轉(zhuǎn)換成正常時間

select FROM_UNIXTIME(time) from test

13.前端可選擇json導出excel

https://github.com/cuikangjie/JsonExportExcel

<div ng-if="selectFun == 'result'">
     <div class="pop-checkbox-block">
         <span>選擇指標:</span>
         <label><input type="checkbox" ng-click="select('uplatAccount',$event)" ng-model="uplatAccount">行業(yè)App賬號</label>
         <label><input type="checkbox" ng-click="select('nickname',$event)" ng-model="nickname">昵稱</label>
         <label><input type="checkbox" ng-click="select('sex',$event)" ng-model="sex">意見主題</label>
         <label><input type="checkbox" ng-click="select('content',$event)" ng-model="content">意見內(nèi)容</label>
          <label><input type="checkbox" ng-click="select('pushTime',$event)" ng-model="pushTime">提交時間</label>
     </div>
    <hr/>
    <div class="pop-file-line">
          <button ng-click="exportExcel(result)">導出</button>
    </div>
</div>

獲取選擇項

    // 獲取選擇功能
        $scope.result = [];
        $scope.select = function(id, event) {
            console.log(event)
            console.log(action)
            var action = event.target;
            if (action.checked) {
                if ($scope.result.indexOf(id) == -1) {
                    $scope.result.push(id);
                }
            } else {
                var idx = $scope.result.indexOf(id);
                if (idx != -1) {
                    $scope.result.splice(idx, 1);
                }
            }
        }

導出excel

    /**
         * 選擇導出excel
         * TODO:等待接口
         * @param paramFilter 選擇參數(shù)數(shù)組
         */
        $scope.exportExcel = function(paramFilter) {
            var option = {}
            option.fileName = '設備列表'
            option.datas = [{
                sheetData: $scope.personinfos,//json
                sheetName: 'sheet',
                sheetFilter: paramFilter,//選擇導出的項,數(shù)組形式
                sheetHeader: paramFilter,//每項的自定義標題
            }]
            var toExcel = new ExportJsonExcel(option);
            toExcel.saveExcel();
        }
最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容