dushibaiyu 6 лет назад
Родитель
Сommit
dfee23a978

+ 8 - 2
JxcClient.pro

@@ -23,9 +23,12 @@ SOURCES += \
     handle/danjumuban.cpp \
     handle/database.cpp \
     handle/httprequest.cpp \
-    handle/logserialport.cpp \
+    handle//seriport/logserialport.cpp \
     handle/remotepackconfig.cpp \
     handle/rtuport.cpp \
+    handle/seriport/assictscalet2000.cpp \
+    handle/seriport/serialbasehandle.cpp \
+    handle/utils/cachefile.cpp \
     handle/utils/rtuhelper.cpp \
     handle/utils/utilsfunc.cpp \
     packinfo.cpp \
@@ -47,9 +50,12 @@ HEADERS += \
     handle/danjumuban.h \
     handle/database.h \
     handle/httprequest.h \
-    handle/logserialport.h \
+    handle/seriport/logserialport.h \
     handle/remotepackconfig.h \
     handle/rtuport.h \
+    handle/seriport/assictscalet2000.h \
+    handle/seriport/serialbasehandle.h \
+    handle/utils/cachefile.h \
     handle/utils/rtuhelper.h \
     handle/utils/utilsfunc.h \
     packinfo.h \

+ 8 - 3
configinfo.cpp

@@ -15,8 +15,13 @@ void ConfigInfo::Start()
     QFileInfo fileInfo(FileName);
     if(!fileInfo.exists()){
         qDebug()<<"配置文件不存在";
-        QMessageBox::information(NULL,"注意","请设置配置");
-        return;
+        Set("url","baseUrl","http://erp.itwsw.cn/api");
+        Set("hardware","printerName","");
+        Set("ElectronicScale","portName","COM1");
+        Set("ElectronicScale","portBaudRate",9600);
+        Set("ElectronicScale","portType",0);
+        m_psetting->sync();
+//        return;
     }
 //   if(fileInfo.exists())
 //   {
@@ -33,7 +38,7 @@ void ConfigInfo::Start()
         //电子秤
         portName = Get("ElectronicScale","portName").toString();//串口名称
         portBaudRate = Get("ElectronicScale","portBaudRate").toString();//串口波特率
-
+        portType = Get("ElectronicScale","portType").toInt();
 
 //   }else{
 //        qDebug()<<"配置文件不存在";

+ 1 - 0
configinfo.h

@@ -18,6 +18,7 @@ public:
     QString printerName; //打印机名称
     QString portName; //电子秤串口名称
     QString portBaudRate; //电子秤串口波特率
+    int portType;
 
 //    QString autoPackUrl;//待入库产品添加接口
 

+ 1 - 1
globalinfo.cpp

@@ -2,7 +2,7 @@
 
 GlobalInfo::GlobalInfo(QObject *parent) : QObject(parent)
 {
-
+    isNoLine = false;
 }
 
 

+ 2 - 0
globalinfo.h

@@ -31,6 +31,8 @@ public:
 
     scaledata GetScaleData();
     void SetScaleData(scaledata data);
+
+    bool isNoLine;
 signals:
 
 public slots:

+ 4 - 1
handle/autopackutils.cpp

@@ -1,4 +1,4 @@
-#include "autopackutils.h"
+#include "autopackutils.h"
 
 /**
  * @brief AutoPackForm工具类
@@ -14,6 +14,9 @@ AutoPackUtils::AutoPackUtils()
  */
 void AutoPackUtils::doSend(QJsonObject json)
 {
+    if(GlobalInfo::this_()->isNoLine){
+        return;
+    }
     if(json.isEmpty()) return;
     //保存码单,上传服务器成功后,以codeSingle为条件更改同步字段;
     this->codeSingle = json["code_single"].toString();

+ 4 - 2
handle/danjumuban.cpp

@@ -222,10 +222,11 @@ QImage DanJuMuBan::mapPrintPackInfo(QMap<QString, QString> product, QStringList
 
 void DanJuMuBan::print(QImage image)
 {
-        QPrinter printer;
+        QPrinter printer(QPrinterInfo::printerInfo(GlobalInfo::this_()->config().printerName));
         printer.setPageSize(QPrinter::Custom);
         printer.setPageSizeMM(QSizeF(100,70));
-        printer.setPrinterName(GlobalInfo::this_()->config().printerName);
+        printer.newPage();
+//        printer.setPrinterName();
         QPainter painter(&printer);                         // 创建一个QPainter对象,并指定绘图设备为一个QPainter对象
         QRect rect =painter.viewport();                     // 获得QPainter对象的视图矩形区域
         QSize size(image.width(),image.height());                            // 获得图像的大小
@@ -234,6 +235,7 @@ void DanJuMuBan::print(QImage image)
         painter.setViewport(rect.x(),rect.y(),size.width()+50,size.height());
         painter.setWindow(image.rect());                      // 设置QPainter窗口大小为图像的大小
         painter.drawImage(0,0,image);                         // 打印图像
+//        printer
 //    }
 }
 

+ 2 - 1
handle/database.cpp

@@ -1,5 +1,6 @@
-#include "database.h"
+#include "database.h"
 #include "QSqlRecord"
+#include <QStringList>
 
 Database::Database(QObject *parent) :
     QObject(parent)

+ 18 - 1
handle/remotepackconfig.cpp

@@ -1,5 +1,7 @@
 #include "remotepackconfig.h"
 #include "globalinfo.h"
+#include "handle/utils/cachefile.h"
+#include <QJsonDocument>
 
 RemotePackConfig::RemotePackConfig(QObject *parent) : QObject(parent)
 {
@@ -98,6 +100,16 @@ void RemotePackConfig::refConfig()
 {
     getDdengji = false;
     GlobalInfo * glo = GlobalInfo::this_();
+    if(glo->isNoLine){
+        CacheFile f;
+        auto dt = f.readFile("config.cache");
+        auto obj = QJsonDocument::fromJson(dt).object();
+        result(200,obj);
+        getDdengji = true;
+        dt = f.readFile("dengjiList.cache");
+        obj = QJsonDocument::fromJson(dt).object();
+        result(200,obj);
+    }
 //    _aid = QString::number(body["user_id"].toInt());
 //    _token = body["access_token"].toString();
     _request.setUserToken(QString::number( glo->user().accountId) ,glo->user().acessToken);
@@ -114,6 +126,8 @@ void RemotePackConfig::result(int code, const QJsonObject & body)
         return;
     }
     if(!getDdengji){
+        CacheFile f;
+        f.writeFile("config.cache",QJsonDocument(body).toJson());
         QJsonArray object = body.value("data").toArray();
         for(int i = 0; i < object.size(); ++ i){
             QJsonObject obj = object.at(i).toObject();
@@ -122,9 +136,12 @@ void RemotePackConfig::result(int code, const QJsonObject & body)
             handle(obj);
         }
         emit configUpdate(_config);
-        refDengJiList();
+if(!GlobalInfo::this_()->isNoLine){refDengJiList();}
+
     } else {
         // TODO: 解析等级列表
+        CacheFile f;
+        f.writeFile("dengjiList.cache",QJsonDocument(body).toJson());
         QJsonArray object = body.value("data").toArray();
         DengJiConfigItem dengJiConfig;
         for(int i = 0; i<object.size();i++){

+ 33 - 34
handle/rtuport.cpp

@@ -1,56 +1,55 @@
-#include "rtuport.h"
+#include "rtuport.h"
 
 RtuPort::RtuPort()
 {
-    m_serialPort = new QSerialPort();
+    m_serialPort = new QSerialPort(this);
+    stard = false;
     //设置参数
 
-    m_serialPort->setPortName(GlobalInfo::this_()->config().portName);
-    m_serialPort->setBaudRate(GlobalInfo::this_()->config().portBaudRate.toInt(),QSerialPort::AllDirections);//设置默认波特率和读写方向
-    m_serialPort->setDataBits(QSerialPort::Data8);		//数据位为8位
-    m_serialPort->setFlowControl(QSerialPort::NoFlowControl);//无流控制
-    m_serialPort->setParity(QSerialPort::NoParity);	//无校验位
-    m_serialPort->setStopBits(QSerialPort::OneStop); //一位停止位
+//    m_serialPort->setPortName(GlobalInfo::this_()->config().portName);
+//    m_serialPort->setBaudRate(GlobalInfo::this_()->config().portBaudRate.toInt());//设置默认波特率和读写方向
+//    m_serialPort->setDataBits(QSerialPort::Data8);		//数据位为8位
+//    m_serialPort->setFlowControl(QSerialPort::NoFlowControl);//无流控制
+//    m_serialPort->setParity(QSerialPort::NoParity);	//无校验位
+//    m_serialPort->setStopBits(QSerialPort::OneStop); //一位停止位
     connect(m_serialPort,SIGNAL(readyRead()),this,SLOT(receiveInfo()));
 
-    ret = QByteArray::fromHex("010300000006C5C8");
-    portTimer = new QTimer(this);
-    connect(portTimer,&QTimer::timeout,this,&RtuPort::portStart);
-    portTimer->start(1000);
+//    ret = QByteArray::fromHex("010300000006C5C8");
+//    portTimer = new QTimer(this);
+//    connect(portTimer,&QTimer::timeout,this,&RtuPort::portStart);
+//    portTimer->start(1000);
+    timer = new QTimer(this);
+    connect(timer,&QTimer::timeout,this,&RtuPort::portWrite);
 }
 
-void RtuPort::portStart()
+void RtuPort::start(QString & name, int band, SerialBaseHandle * handle)
 {
-    m_serialPort->open(QIODevice::ReadWrite);
-    if(!m_serialPort->isOpen()){
-        qDebug()<<"串口未打开";
-        return;
-    }
-    qDebug("串口已开启");
-    portTimer->stop();
-    timer = new QTimer(this);
-    connect(timer,&QTimer::timeout,this,&RtuPort::portWrite);
-    timer->start(200);
+    if(m_serialPort->isOpen()) m_serialPort->close();
+     m_serialPort->setPortName(name);
+      m_serialPort->setBaudRate(band);
+      m_serialPort->open(QIODevice::ReadWrite);
+    if(!timer->isActive())
+        timer->start(200);
+    stard = true;
+
 }
 
 void RtuPort::portWrite()
 {
-//    qDebug()<<"测试";
-//    if(hexData.isEmpty()){
-//        qDebug()<<"null";
-//        timer->stop();
-//        portTimer->start(1000);
-//    }
-    m_serialPort->write(ret);
+    if(!m_serialPort->isOpen()){
+        m_serialPort->open(QIODevice::ReadWrite);
+        return;
+    }
+    if(_handle && _handle->needSend()){
+    m_serialPort->write(_handle->sendData());
+    }
 }
 
 void RtuPort::receiveInfo()
 {
     QByteArray info = m_serialPort->readAll();
-    QByteArray hexData = info.toHex().data();
-//    qDebug()<<"receiveInfo测试:"<<hexData.toUpper();
-    log.readed(info);
-//    QByteArray data;
+    if(_handle)
+      _handle->handle(info);
 
 }
 

+ 8 - 11
handle/rtuport.h

@@ -1,13 +1,12 @@
-#ifndef RTUPORT_H
+#ifndef RTUPORT_H
 #define RTUPORT_H
 
 #include <QObject>
 #include "QDebug"
-#include "QtSerialPort/QSerialPort"
-#include "QtSerialPort/QSerialPortInfo"
+#include <QSerialPort>
 #include "QTimer"
-#include "logserialport.h"
 #include "globalinfo.h"
+#include "handle/seriport/serialbasehandle.h"
 
 
 class RtuPort : public QObject
@@ -16,20 +15,18 @@ class RtuPort : public QObject
 
 public:
     RtuPort();
-    void portStart();
 
+    void start(QString & name, int band, SerialBaseHandle * handle);
+
+    inline bool isStart() const {return stard;}
 private slots:
     void receiveInfo();
     void portWrite();
 private:
     QSerialPort *m_serialPort;
-    QStringList m_serialPortName;
     QTimer *timer;
-    QTimer *portTimer;
-    LogSerialPort log;
-    QByteArray ret;
-
-
+    SerialBaseHandle * _handle;
+    bool stard;
 };
 
 #endif // RTUPORT_H

+ 74 - 0
handle/seriport/assictscalet2000.cpp

@@ -0,0 +1,74 @@
+#include "assictscalet2000.h"
+#include <QList>
+#include "globalinfo.h"
+
+AssicTScaleT2000::AssicTScaleT2000()
+{
+
+}
+
+AssicTScaleT2000::~AssicTScaleT2000()
+{
+
+}
+
+bool AssicTScaleT2000::needSend()
+{
+    return false;
+}
+
+QByteArray AssicTScaleT2000::sendData()
+{
+    return QByteArray();
+}
+
+
+void AssicTScaleT2000::handle(QByteArray &data)
+{
+    int newstart = 0;
+    int scan = m_inbuffer.size();
+
+    m_inbuffer.append(data);
+
+    while (newstart < m_inbuffer.size()) {
+        int start = newstart;
+        int end = m_inbuffer.indexOf('\n', scan);
+        if (end < 0) {
+            m_inbuffer.remove(0, start);
+            return;
+        }
+        newstart = end + 1;
+        scan = newstart;
+        if (end == start)
+            continue;
+        if (m_inbuffer.at(end - 1) == '\r') {
+            --end;
+            if (end == start)
+                continue;
+        }
+        QByteArray line(m_inbuffer.constData() + start, end - start);
+        readData(line);
+    }
+    m_inbuffer.clear();
+
+}
+
+void AssicTScaleT2000::readData(QByteArray & data)
+{
+    QList<QByteArray> list = data.split(',');
+    auto buff = list.last();
+    const char * from = buff.constData();
+    const char *to = from + buff.size();
+    const char *inner;
+
+    // Token is a sequence of numbers.
+    for (inner = from; inner != to; ++inner)
+        if (*inner != '.' && (*inner < '0' || *inner > '9'))
+            break;
+    if (from != inner) {
+        double token = QByteArray(from, inner - from).toDouble();
+        scaledata _scaledata;
+        _scaledata.gross_widget = token;
+        GlobalInfo::this_()->SetScaleData(_scaledata);
+    }
+}

+ 19 - 0
handle/seriport/assictscalet2000.h

@@ -0,0 +1,19 @@
+#ifndef ASSICTSCALET2000_H
+#define ASSICTSCALET2000_H
+
+#include "serialbasehandle.h"
+
+class AssicTScaleT2000 : public SerialBaseHandle
+{
+public:
+    AssicTScaleT2000();
+    ~AssicTScaleT2000();
+    virtual bool needSend();
+    virtual QByteArray sendData();
+    virtual void handle(QByteArray & data);
+
+    void readData(QByteArray & data);
+    QByteArray m_inbuffer;
+};
+
+#endif // ASSICTSCALET2000_H

+ 24 - 4
handle/logserialport.cpp → handle/seriport/logserialport.cpp

@@ -1,18 +1,23 @@
 #include "logserialport.h"
 #include <QCoreApplication>
 #include <QByteArray>
-#include "utils/utilsfunc.h"
+#include "handle/utils/utilsfunc.h"
 
 
 #ifdef _MSC_VER
 #pragma execution_character_set("utf-8")
 #endif
 
-LogSerialPort::LogSerialPort(QObject *parent) : QObject(parent)
+LogSerialPort::LogSerialPort()
 {
     buchang  = 0;
     min = 0;
     max = 999;
+    ret = QByteArray::fromHex("010300000006C5C8");
+}
+
+LogSerialPort::~LogSerialPort()
+{
 }
 
 float LogSerialPort::toFloat(const QByteArray & ray){
@@ -25,6 +30,21 @@ float LogSerialPort::toFloat(const QByteArray & ray){
     return value;
 }
 
+bool LogSerialPort::needSend()
+{
+    return true;
+}
+
+QByteArray LogSerialPort::sendData()
+{
+    return ret;
+}
+
+void LogSerialPort::handle(QByteArray & data)
+{
+    doHandle(data);
+}
+
 void LogSerialPort::doHandle(const QByteArray & data)
 {
     if(data.at(1) != 0x03) return;
@@ -66,6 +86,6 @@ void LogSerialPort::doHandle(const QByteArray & data)
 //    save(0,tm,rv);
 //    emit newValue(0,tm.toMSecsSinceEpoch(),rv);
 //    qDebug()<<rv;
-    scaledata.gross_widget = rv;
-    GlobalInfo::this_()->SetScaleData(scaledata);
+    _scaledata.gross_widget = rv;
+    GlobalInfo::this_()->SetScaleData(_scaledata);
 }

+ 13 - 19
handle/logserialport.h → handle/seriport/logserialport.h

@@ -1,42 +1,36 @@
-#ifndef LOGSERIALPORT_H
+#ifndef LOGSERIALPORT_H
 #define LOGSERIALPORT_H
 
 #include <QObject>
 #include <QWidget>
 #include <QSerialPort>
 #include <QQueue>
-#include "utils/rtuhelper.h"
+#include "handle/utils/rtuhelper.h"
 #include <QPair>
 #include <QDateTime>
 #include <QFile>
 #include <QTimer>
 #include "QDebug"
 #include "globalinfo.h"
+#include "serialbasehandle.h"
 
 #ifdef _MSC_VER
 #pragma execution_character_set("utf-8")
 #endif
 
-class LogSerialPort : public QObject,public UtilsFun::RTUHelper
+class LogSerialPort : public UtilsFun::RTUHelper, public SerialBaseHandle
 {
-    Q_OBJECT
 public:
-    explicit LogSerialPort(QObject *parent = nullptr);
-
+    explicit LogSerialPort();
+    ~LogSerialPort();
 //    inline bool isStart() const {return started;}
 //    inline bool isOpened() const {return opened;}
     float toFloat(const QByteArray & ray);
-signals:
-//    void refValue();
-//    void newValue(int id,qint64 tm, double v);
-public slots:
-//    void open(const QString & name, int bandwith);
-//    void close();
-
-//    void checkBuchang(double buchang, double max, double min);
-private slots:
-//    void doTimerOut();
-//    void readData();
+
+    bool needSend();
+    QByteArray sendData();
+    void handle(QByteArray & data);
+
     void doHandle(const QByteArray & data);
 
 //    void save(int, const QDateTime &tm, double v);
@@ -51,8 +45,8 @@ private:
 
     QByteArray _getData;
     QByteArray _resetData;
-    scaledata scaledata;
-
+    scaledata _scaledata;
+    QByteArray ret;
 
     double buchang;
     double max;

+ 30 - 0
handle/seriport/serialbasehandle.cpp

@@ -0,0 +1,30 @@
+#include "serialbasehandle.h"
+#include "logserialport.h"
+#include "assictscalet2000.h"
+
+SerialBaseHandle::SerialBaseHandle()
+{
+
+}
+
+SerialBaseHandle::~SerialBaseHandle()
+{
+
+}
+
+
+SerialBaseHandle * SerialBaseHandle::getHandler(int type, const QString & result)
+{
+    SerialBaseHandle *ret = nullptr;
+    switch (type) {
+        case 0:
+        ret = new LogSerialPort();
+        break;
+    case 1:
+        ret = new AssicTScaleT2000();
+        break;
+    default:
+        break;
+    }
+    return ret;
+}

+ 20 - 0
handle/seriport/serialbasehandle.h

@@ -0,0 +1,20 @@
+#ifndef SERIALBASEHANDLE_H
+#define SERIALBASEHANDLE_H
+
+#include <QByteArray>
+#include <QString>
+
+class SerialBaseHandle
+{
+public:
+    SerialBaseHandle();
+    virtual ~SerialBaseHandle();
+
+    virtual bool needSend() = 0;
+    virtual QByteArray sendData() = 0;
+    virtual void handle(QByteArray & data) = 0;
+
+    static SerialBaseHandle * getHandler(int type, const QString & result = QString());
+};
+
+#endif // SERIALBASEHANDLE_H

+ 34 - 0
handle/utils/cachefile.cpp

@@ -0,0 +1,34 @@
+#include "cachefile.h"
+
+#include <QFile>
+
+CacheFile::CacheFile()
+{
+    dir = QDir::home();
+    if(!dir.exists("jxcCache")){
+        dir.mkdir("jxcCache");
+    }
+    dir.cd("jxcCache");
+}
+
+
+bool CacheFile::writeFile(const QString & name, const QByteArray & data)
+{
+    QFile f(dir.absoluteFilePath(name));
+    if(f.open(QFile::WriteOnly)){
+        f.write(data);
+        f.close();
+    }
+    return false;
+}
+
+QByteArray CacheFile::readFile(const QString & name)
+{
+    QByteArray dt;
+    QFile f(dir.absoluteFilePath(name));
+    if(f.open(QFile::ReadOnly)){
+        dt = f.readAll();
+        f.close();
+    }
+    return dt;
+}

+ 18 - 0
handle/utils/cachefile.h

@@ -0,0 +1,18 @@
+#ifndef CACHEFILE_H
+#define CACHEFILE_H
+
+#include <QDir>
+
+class CacheFile
+{
+public:
+    CacheFile();
+
+    bool writeFile(const QString & name, const QByteArray & data);
+
+    QByteArray readFile(const QString & name);
+private:
+    QDir dir;
+};
+
+#endif // CACHEFILE_H

+ 4 - 1
handle/utils/rtuhelper.cpp

@@ -1,10 +1,13 @@
-#include "rtuhelper.h"
+#include "rtuhelper.h"
+
+
 #ifdef _MSC_VER
 #pragma execution_character_set("utf-8")
 #endif
 
 
 namespace UtilsFun {
+
 RTUHelper::RTUHelper():
     readType(SubAddress),toReadlen(0),_checkSubAddress(false)
 {

+ 1 - 0
handle/utils/rtuhelper.h

@@ -49,6 +49,7 @@ private:
     bool _checkSubAddress;
     QByteArray _subAddress;
 };
+
 }
 
 #endif // RTUHELPER_H

+ 9 - 2
mainwindow.cpp

@@ -1,5 +1,7 @@
 #include "mainwindow.h"
 #include "ui_mainwindow.h"
+#include "handle/seriport/serialbasehandle.h"
+
 MainWindow::MainWindow(QWidget *parent)
     : QMainWindow(parent)
     , ui(new Ui::MainWindow)
@@ -18,8 +20,6 @@ MainWindow::MainWindow(QWidget *parent)
     connect(ui->pageAutoPack,&AutoPackForm::djmbbox,this,&MainWindow::changedjmb);
     connect(ui->widgetLogin,&LoginForm::SettingsClicked,this,&MainWindow::changeToSettings);
 
-    rtuport.portStart();
-
     database.openDB();
     database.createDetailsDatabase();
     database.createProductDatabase();
@@ -97,6 +97,13 @@ void MainWindow::backMenu()
         return;
     }
     ui->stackedWidget->setCurrentWidget(ui->pageMain);
+    if(!rtuport.isStart()){
+        auto go = GlobalInfo::this_();
+        ConfigInfo info;
+        info.Start();
+        auto handle = SerialBaseHandle::getHandler(info.portType,"");
+        rtuport.start(info.portName,info.portBaudRate.toInt(),handle);
+    }
 }
 
 void MainWindow::changedjmb(QImage image)

+ 6 - 6
mainwindow.ui

@@ -33,7 +33,7 @@
     <item>
      <widget class="QStackedWidget" name="stackedWidget">
       <property name="currentIndex">
-       <number>8</number>
+       <number>3</number>
       </property>
       <widget class="QWidget" name="pageMain">
        <layout class="QHBoxLayout" name="horizontalLayout_2">
@@ -296,14 +296,14 @@ color: rgb(255, 255, 255);</string>
            <widget class="LoginForm" name="widgetLogin" native="true">
             <property name="minimumSize">
              <size>
-              <width>350</width>
-              <height>200</height>
+              <width>500</width>
+              <height>500</height>
              </size>
             </property>
             <property name="maximumSize">
              <size>
-              <width>350</width>
-              <height>200</height>
+              <width>500</width>
+              <height>500</height>
              </size>
             </property>
            </widget>
@@ -353,7 +353,7 @@ color: rgb(255, 255, 255);</string>
      <x>0</x>
      <y>0</y>
      <width>896</width>
-     <height>26</height>
+     <height>30</height>
     </rect>
    </property>
   </widget>

+ 13 - 0
widget/autopackform.cpp

@@ -1,6 +1,8 @@
 #include "autopackform.h"
 #include "ui_autopackform.h"
 #include "globalinfo.h"
+#include <QMessageBox>
+#include <QTimer>
 
 AutoPackForm::AutoPackForm(QWidget *parent) :
     QWidget(parent),
@@ -13,6 +15,7 @@ AutoPackForm::AutoPackForm(QWidget *parent) :
     ui->addBoxList->setDisabled(true);
     ui->addPackList->setDisabled(true);
     netNum = 0.00;
+    ui->widgetTotle->hide();
 }
 
 AutoPackForm::~AutoPackForm()
@@ -196,3 +199,13 @@ void AutoPackForm::upDengjiInfo(const QList<DengJiConfigItem> & dengJis)
         }
     }
 }
+
+void AutoPackForm::on_handleRead_clicked()
+{
+    scaleData();
+}
+
+void AutoPackForm::on_pushSync_clicked()
+{
+
+}

+ 6 - 1
widget/autopackform.h

@@ -5,7 +5,7 @@
 #include "globalinfo.h"
 #include "handle/remotepackconfig.h"
 #include "packinfo.h"
-#include "httprequestid.h"
+//#include "httprequestid.h"
 #include "handle/danjumuban.h"
 #include "handle/database.h"
 #include "handle/autopackutils.h"
@@ -52,6 +52,11 @@ private slots:
 
 //    void packData();
 
+
+    void on_handleRead_clicked();
+
+    void on_pushSync_clicked();
+
 private:
     Ui::AutoPackForm *ui;
     ProjectInfo _info;

+ 1 - 1
widget/autopackform.ui

@@ -352,7 +352,7 @@ color: rgb(0, 170, 255);</string>
          </widget>
         </item>
         <item>
-         <widget class="QPushButton" name="pushButton_17">
+         <widget class="QPushButton" name="pushSync">
           <property name="text">
            <string>同步</string>
           </property>

+ 2 - 2
widget/fixedweightpackform.h

@@ -1,10 +1,10 @@
-#ifndef FIXEDWEIGHTPACKFORM_H
+#ifndef FIXEDWEIGHTPACKFORM_H
 #define FIXEDWEIGHTPACKFORM_H
 
 #include <QWidget>
 #include "handle/remotepackconfig.h"
 #include "packinfo.h"
-#include "httprequestid.h"
+//#include "httprequestid.h"
 #include "handle/danjumuban.h"
 #include "handle/database.h"
 #include "handle/autopackutils.h"

+ 27 - 0
widget/loginform.cpp

@@ -2,6 +2,8 @@
 #include "ui_loginform.h"
 #include <QMessageBox>
 #include "globalinfo.h"
+#include "handle/utils/cachefile.h"
+#include <QJsonDocument>
 
 LoginForm::LoginForm(QWidget *parent) :
     QWidget(parent),
@@ -79,6 +81,9 @@ void LoginForm::result(int code, const QJsonObject & body)
         msg.exec();
         return;
     }
+
+    CacheFile cf;
+    cf.writeFile("userlogin.cache",QJsonDocument(body).toJson());
     auto data  = body.value("data").toObject();
     UserInfo user;
     user.accountId = data["account_id"].toInt();
@@ -95,3 +100,25 @@ void LoginForm::on_pushButton_2_clicked()
 {
     emit SettingsClicked();
 }
+
+void LoginForm::on_pushButton_clicked()
+{
+    CacheFile cf;
+    auto dt = cf.readFile("userlogin.cache");
+    UserInfo user;
+    QJsonObject obj = QJsonDocument::fromJson(dt).object();
+    if(!obj.isEmpty()){
+        auto data  = obj.value("data").toObject();
+        user.accountId = data["account_id"].toInt();
+        user.userId = data["user_id"].toInt();
+        user.userName = data["name"].toString();
+        user.headPortrait = data["head_portrait"].toString();
+        user.isVip = data["is_vip"].toInt(-1) == 1 ? true : false;
+        user.acessToken = data["access_token"].toString();
+    } else {
+        QMessageBox::warning(this,tr("请先成功登陆一次!"),tr("请先成功登陆一次!"));
+    }
+    GlobalInfo::this_()->isNoLine = true;
+    GlobalInfo::this_()->setUser(user);
+     emit loginFinish();
+}

+ 2 - 0
widget/loginform.h

@@ -27,6 +27,8 @@ private slots:
     void clear();
     void on_pushButton_2_clicked();
 
+    void on_pushButton_clicked();
+
 private:
     HttpRequest  * request();
 private:

+ 112 - 103
widget/loginform.ui

@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>350</width>
-    <height>200</height>
+    <width>395</width>
+    <height>241</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -16,107 +16,116 @@
   <property name="styleSheet">
    <string notr="true">background-color: rgb(255, 255, 255);</string>
   </property>
-  <widget class="QWidget" name="widget" native="true">
-   <property name="geometry">
-    <rect>
-     <x>0</x>
-     <y>0</y>
-     <width>351</width>
-     <height>201</height>
-    </rect>
-   </property>
-   <property name="styleSheet">
-    <string notr="true">background-color: rgb(185, 229, 255);</string>
-   </property>
-   <widget class="QLabel" name="label_2">
-    <property name="geometry">
-     <rect>
-      <x>20</x>
-      <y>90</y>
-      <width>58</width>
-      <height>18</height>
-     </rect>
-    </property>
-    <property name="text">
-     <string>密码:</string>
-    </property>
-   </widget>
-   <widget class="QLineEdit" name="lineUser">
-    <property name="geometry">
-     <rect>
-      <x>100</x>
-      <y>40</y>
-      <width>191</width>
-      <height>32</height>
-     </rect>
-    </property>
-   </widget>
-   <widget class="QLabel" name="status">
-    <property name="geometry">
-     <rect>
-      <x>60</x>
-      <y>10</y>
-      <width>201</width>
-      <height>21</height>
-     </rect>
-    </property>
-    <property name="text">
-     <string>正在登陆中······</string>
-    </property>
-   </widget>
-   <widget class="QLabel" name="label">
-    <property name="geometry">
-     <rect>
-      <x>20</x>
-      <y>50</y>
-      <width>58</width>
-      <height>18</height>
-     </rect>
-    </property>
-    <property name="text">
-     <string>用户名:</string>
-    </property>
-   </widget>
-   <widget class="QLineEdit" name="linePass">
-    <property name="geometry">
-     <rect>
-      <x>100</x>
-      <y>80</y>
-      <width>191</width>
-      <height>31</height>
-     </rect>
-    </property>
-   </widget>
-   <widget class="QPushButton" name="pushLogin">
-    <property name="geometry">
-     <rect>
-      <x>70</x>
-      <y>130</y>
-      <width>181</width>
-      <height>51</height>
-     </rect>
-    </property>
-    <property name="styleSheet">
-     <string notr="true">background-color: rgb(129, 207, 255);</string>
-    </property>
-    <property name="text">
-     <string>登陆</string>
-    </property>
-   </widget>
-   <widget class="QPushButton" name="pushButton_2">
-    <property name="geometry">
-     <rect>
-      <x>280</x>
-      <y>160</y>
-      <width>51</width>
-      <height>31</height>
-     </rect>
-    </property>
-    <property name="text">
-     <string>设置</string>
-    </property>
-   </widget>
-  </widget>
+  <layout class="QHBoxLayout" name="horizontalLayout">
+   <item>
+    <widget class="QWidget" name="widget" native="true">
+     <property name="styleSheet">
+      <string notr="true">background-color: rgb(185, 229, 255);</string>
+     </property>
+     <widget class="QLabel" name="label_2">
+      <property name="geometry">
+       <rect>
+        <x>20</x>
+        <y>90</y>
+        <width>58</width>
+        <height>18</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string>密码:</string>
+      </property>
+     </widget>
+     <widget class="QLineEdit" name="lineUser">
+      <property name="geometry">
+       <rect>
+        <x>100</x>
+        <y>40</y>
+        <width>191</width>
+        <height>32</height>
+       </rect>
+      </property>
+     </widget>
+     <widget class="QLabel" name="status">
+      <property name="geometry">
+       <rect>
+        <x>60</x>
+        <y>10</y>
+        <width>201</width>
+        <height>21</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string>正在登陆中······</string>
+      </property>
+     </widget>
+     <widget class="QLabel" name="label">
+      <property name="geometry">
+       <rect>
+        <x>20</x>
+        <y>50</y>
+        <width>58</width>
+        <height>18</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string>用户名:</string>
+      </property>
+     </widget>
+     <widget class="QLineEdit" name="linePass">
+      <property name="geometry">
+       <rect>
+        <x>100</x>
+        <y>80</y>
+        <width>191</width>
+        <height>31</height>
+       </rect>
+      </property>
+     </widget>
+     <widget class="QPushButton" name="pushLogin">
+      <property name="geometry">
+       <rect>
+        <x>100</x>
+        <y>115</y>
+        <width>181</width>
+        <height>51</height>
+       </rect>
+      </property>
+      <property name="styleSheet">
+       <string notr="true">background-color: rgb(129, 207, 255);</string>
+      </property>
+      <property name="text">
+       <string>登陆</string>
+      </property>
+     </widget>
+     <widget class="QPushButton" name="pushButton_2">
+      <property name="geometry">
+       <rect>
+        <x>310</x>
+        <y>190</y>
+        <width>51</width>
+        <height>31</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string>设置</string>
+      </property>
+     </widget>
+     <widget class="QPushButton" name="pushButton">
+      <property name="geometry">
+       <rect>
+        <x>0</x>
+        <y>180</y>
+        <width>91</width>
+        <height>41</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string>离线进入</string>
+      </property>
+     </widget>
+    </widget>
+   </item>
+  </layout>
  </widget>
  <resources/>
  <connections/>

+ 12 - 5
widget/settingsform.cpp

@@ -1,5 +1,6 @@
-#include "settingsform.h"
+#include "settingsform.h"
 #include "ui_settingsform.h"
+#include <QPrinterInfo>
 
 SettingsForm::SettingsForm(QWidget *parent) :
     QWidget(parent),
@@ -8,9 +9,10 @@ SettingsForm::SettingsForm(QWidget *parent) :
     ui->setupUi(this);
     Init();
     ui->baseUrlLine->setText(config.baseUrl);
-    ui->printerName->setText(config.printerName);
+    ui->printerName->setCurrentText(config.printerName);
     ui->portName->setCurrentText(config.portName);
     ui->portBaudRate->setCurrentText(config.portBaudRate);
+    ui->comboBox_2->setCurrentIndex(config.portType);
 }
 
 SettingsForm::~SettingsForm()
@@ -21,6 +23,12 @@ SettingsForm::~SettingsForm()
 void SettingsForm::Init()
 {
     //串口名称
+    foreach(const QPrinterInfo &info,QPrinterInfo::availablePrinters())
+    {
+       ui->printerName->addItem(info.printerName());
+//               qDebug()<<info.portName();
+    }
+
     foreach(const QSerialPortInfo &info,QSerialPortInfo::availablePorts())
     {
        ui->portName->addItem(info.portName());
@@ -29,7 +37,6 @@ void SettingsForm::Init()
 
     //串口波特率
     QStringList Baudlist;
-    Baudlist.clear();
     Baudlist<<"300"<<"600"<<"2400"<<"4800"<<"9600"<<"19200"<<"56000"<<"57600"<<"115200"<<"128000"<<"256000"<<"921600";
     ui->portBaudRate->addItems(Baudlist);
 }
@@ -42,8 +49,8 @@ void SettingsForm::on_back_btn_clicked()
 void SettingsForm::on_save_btn_clicked()
 {
     config.Set("url","baseUrl",ui->baseUrlLine->text());
-    config.Set("hardware","printerName",ui->printerName->text());
+    config.Set("hardware","printerName",ui->printerName->currentText());
     config.Set("ElectronicScale","portName",ui->portName->currentText());
     config.Set("ElectronicScale","portBaudRate",ui->portBaudRate->currentText());
-    config.Start();
+    config.Set("ElectronicScale","portType",ui->comboBox_2->currentIndex());
 }

+ 2 - 2
widget/settingsform.h

@@ -1,9 +1,9 @@
-#ifndef SETTINGSFORM_H
+#ifndef SETTINGSFORM_H
 #define SETTINGSFORM_H
 
 #include <QWidget>
 #include "configinfo.h"
-#include "QtSerialPort/QSerialPortInfo"
+#include <QSerialPortInfo>
 
 namespace Ui {
 class SettingsForm;

+ 20 - 19
widget/settingsform.ui

@@ -104,6 +104,16 @@
          <height>22</height>
         </rect>
        </property>
+       <item>
+        <property name="text">
+         <string>ModbusRTU</string>
+        </property>
+       </item>
+       <item>
+        <property name="text">
+         <string>Tsale-ASSIC</string>
+        </property>
+       </item>
       </widget>
       <widget class="QLabel" name="label">
        <property name="geometry">
@@ -141,25 +151,6 @@
         <string>波特率:</string>
        </property>
       </widget>
-      <widget class="QLineEdit" name="printerName">
-       <property name="geometry">
-        <rect>
-         <x>150</x>
-         <y>30</y>
-         <width>301</width>
-         <height>21</height>
-        </rect>
-       </property>
-       <property name="styleSheet">
-        <string notr="true">background-color: rgb(255, 255, 255);</string>
-       </property>
-       <property name="text">
-        <string/>
-       </property>
-       <property name="placeholderText">
-        <string>打印机名称</string>
-       </property>
-      </widget>
       <widget class="QComboBox" name="portName">
        <property name="geometry">
         <rect>
@@ -244,6 +235,16 @@
         <string>规则</string>
        </property>
       </widget>
+      <widget class="QComboBox" name="printerName">
+       <property name="geometry">
+        <rect>
+         <x>80</x>
+         <y>20</y>
+         <width>331</width>
+         <height>32</height>
+        </rect>
+       </property>
+      </widget>
      </widget>
     </widget>
    </item>

+ 2 - 2
widget/uncertainweightpackform.h

@@ -1,10 +1,10 @@
-#ifndef UNCERTAINWEIGHTPACKFORM_H
+#ifndef UNCERTAINWEIGHTPACKFORM_H
 #define UNCERTAINWEIGHTPACKFORM_H
 
 #include <QWidget>
 #include "handle/remotepackconfig.h"
 #include "packinfo.h"
-#include "httprequestid.h"
+//#include "httprequestid.h"
 #include "handle/danjumuban.h"
 #include "handle/database.h"
 #include "handle/autopackutils.h"