• 安卓端数据导出成txt文件


      toExport() {
          if (this.dataList == false) {
            this.$createDialog({
              type: "alert",
              content: "数据為空",
              confirmBtn: "確定",
              icon: "cubeic-alert"
            }).show();
          } else {
            var that = this;
            this.$createDialog({
              type: "confirm",
              icon: "cubeic-alert",
              content: "確定導出嗎?",
              confirmBtn: {
                text: "確定",
                active: true,
                disabled: false,
                href: "javascript:;"
              },
              cancelBtn: {
                text: "取消",
                active: false,
                disabled: false,
                href: "javascript:;"
              },
              onConfirm: () => {
                var data = [];
                this.dataList.forEach(x => {
                  var datas = x.counter + "," + x.barcode + "," + x.qty + "
    ";
                  //var datas = x.counter + "," + x.barcode + "," + x.qty;
                  data.push(datas);
                });
                //合并数组为字符串
                var temp_string = data.join("");
                //alert(temp_string)
                //alert(window.requestFileSystem)
    
                window.requestFileSystem(
                  LocalFileSystem.PERSISTENT,
                  0,
                  function(fs) {
                    //alert("open: " + fs.name);
                    fs.root.getFile(
                      "stocking.txt",
                      { create: true, exclusive: false },
                      function(fileEntry) {
                        //alert(fileEntry);
                        //alert("is file?" + fileEntry.isFile.toString());
                        //文件内容
                        //alert (typeof temp_string)
                        // alert("插入的内容是"+temp_string)
                        var dataObj = new Blob([temp_string], {
                          type: "text/plain"
                        });
                        // var dataObj2 = new Blob(["temp_string"], {
                        //   type: "text/plain"
                        // });
                        //写入文件
                        that.writeFile(fileEntry, dataObj);
                        //that.writeFile(fileEntry, dataObj2);
                      },
                      that.onErrorCreateFile
                    );
                  },
                  that.onErrorLoadFs
                );
              }
            }).show();
          }
          //持久化数据保存
        },
        writeFile(fileEntry, dataObj) {
           var that=this;
          //创建一个写入对象
          fileEntry.createWriter(function(fileWriter) {
            //文件写入成功
            fileWriter.onwriteend = function() {
               that.contents="數據保存成功";
               that.showPopup();
            };
    
            //文件写入失败
            fileWriter.onerror = function(e) {
              that.contents="數據保存失敗";
               that.showPopup();
            };
    
            //写入文件
            fileWriter.write(dataObj);
          });
        },
  • 相关阅读:
    C++ Builder XE2随意学习 (5) > 我的学习路线
    麻省理工公开课:电路和电子学 (2) > 基本电路分析法
    C++ Builder XE2随意学习 (4) > Delphi XE2官方视频教程31天
    日志收集系统elk
    mysql笔记第一天: 介绍和MySQL编译安装
    rsync服务搭建2018.5.8 [优化后最终版]
    docker基础使用和资源限制
    zabbix第一天 zabbix安装,添加监控项
    你好,测试markdown
    LVM扩容案例
  • 原文地址:https://www.cnblogs.com/huanhuan55/p/10095574.html
Copyright © 2020-2023  润新知