代码拉取完成,页面将自动刷新
package main
//go:generate go get -u github.com/jteeuwen/go-bindata/...
//go:generate
/*
go-bindata -pkg main -o assets.go -prefix assets/ \
assets/ assets/vendor \
assets/vendor/bootstrap \
assets/vendor/echarts \
assets/vendor/echarts/chart
*/
/*
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
const char* build_time(void)
{
int Year, Month, Day;
//static const char* psz_build_time = "["__DATE__ " " __TIME__ "]";
//return psz_build_time;
static const char *pMonth[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
static const char* Date = __DATE__;//取编译时间
int i;
for(i = 0; i < 12; i++)
if(memcmp(Date, pMonth[i], 3) == 0)
Month = i + 1, i = 12;
Year = atoi(Date + 9); //Date[9]为2位年份,Date[7]为完整年份
Day = atoi(Date + 4);
char* Str = (char *)malloc(9);
sprintf(Str, "20%02d%02d%02d", Year, Month, Day);//任意格式化
return Str;
}
*/
import "C"
import (
"bytes"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"mime"
"net"
"net/http"
"net/url"
"os"
"path"
"path/filepath"
"strconv"
"strings"
"time"
"defer-analyse/service"
"defer-analyse/utils"
"github.com/zserge/webview"
)
var (
buildTime = C.GoString(C.build_time())
)
func BuildTime() string {
return buildTime
}
const (
windowWidth = 1280
windowHeight = 800
)
type JsonResult struct {
msg string `json:"msg"`
}
func startServer() string {
//ln, err := net.Listen("tcp", "127.0.0.1:12345")
ln, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
log.Fatal(err)
}
go func() {
defer ln.Close()
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
path := r.URL.Path
//fmt.Println("path = ", path, r.URL.RequestURI())
var file_id = ""
var pageNumber = ""
var pageSize = ""
r.ParseForm()
if len(r.Form["file_id"]) > 0 {
file_id = r.Form["file_id"][0]
//fmt.Println("file_id>>>>", r.Form["file_id"][0])
}
if len(r.Form["pageNumber"]) > 0 {
pageNumber = r.Form["pageNumber"][0]
//fmt.Println("pageNumber>>>>", r.Form["pageNumber"][0])
}
if len(r.Form["pageSize"]) > 0 {
pageSize = r.Form["pageSize"][0]
//fmt.Println("pageSize>>>>", r.Form["pageSize"][0])
}
if len(path) > 0 && path[0] == '/' {
path = path[1:]
}
//fmt.Println("path = ", path, r.URL.RequestURI())
if path == "" {
path = "index.html"
} else if path == "indexmonth" {
path = "indexmonth.html"
} else if path == "indexyear" {
path = "indexyear.html"
} else if path == "detail" {
path = "detail.html"
} else if path == "detailmonth" {
path = "detailmonth.html"
} else if path == "detailyear" {
path = "detailyear.html"
} else if path == "middetail" {
path = "middetail.html"
} else if path == "middetailmonth" {
path = "middetailmonth.html"
} else if path == "middetailyear" {
path = "middetailyear.html"
} else if path == "analyse" {
path = "analyse.html"
} else if path == "analysemonth" {
path = "analysemonth.html"
} else if path == "analyseyear" {
path = "analyseyear.html"
}
if path == "rest/defer_detail.json" {
deferData := new(service.DeferData)
deferData.GetDefectDetailByFile(file_id, pageNumber, pageSize)
jsonBytes, err := json.Marshal(deferData)
if err != nil {
fmt.Println(err)
}
//jsonBytes, err := service.GetDefectFile()
//fmt.Println("GetDefectDetailByFile jsonBytes>>", string(jsonBytes))
if err != nil {
fmt.Println(err)
}
_, err2 := w.Write([]byte(jsonBytes))
fmt.Println("err", err2)
} else if path == "rest/defer_detail_month.json" {
deferData := new(service.DeferData)
deferData.GetDefectDetailMonthByFile(file_id, pageNumber, pageSize)
jsonBytes, err := json.Marshal(deferData)
if err != nil {
fmt.Println(err)
}
//jsonBytes, err := service.GetDefectFile()
//fmt.Println("GetDefectDetailByFile jsonBytes>>", string(jsonBytes))
if err != nil {
fmt.Println(err)
}
_, err2 := w.Write([]byte(jsonBytes))
fmt.Println("err", err2)
} else if path == "rest/defer_detail_year.json" {
deferData := new(service.DeferData)
deferData.GetDefectDetailYearByFile(file_id, pageNumber, pageSize)
jsonBytes, err := json.Marshal(deferData)
if err != nil {
fmt.Println(err)
}
//jsonBytes, err := service.GetDefectFile()
//fmt.Println("GetDefectDetailByFile jsonBytes>>", string(jsonBytes))
if err != nil {
fmt.Println(err)
}
_, err2 := w.Write([]byte(jsonBytes))
fmt.Println("err", err2)
} else if path == "rest/mid_defer_detail.json" {
deferData := new(service.DeferData)
deferData.GetMidDefectDetailByFile(file_id, pageNumber, pageSize)
jsonBytes, err := json.Marshal(deferData)
if err != nil {
fmt.Println(err)
}
//jsonBytes, err := service.GetDefectFile()
//fmt.Println("GetDefectDetailByFile jsonBytes>>", string(jsonBytes))
if err != nil {
fmt.Println(err)
}
_, err2 := w.Write([]byte(jsonBytes))
fmt.Println("err", err2)
} else if path == "rest/mid_defer_detail_month.json" {
deferData := new(service.DeferData)
deferData.GetMidDefectDetailMonthByFile(file_id, pageNumber, pageSize)
jsonBytes, err := json.Marshal(deferData)
if err != nil {
fmt.Println(err)
}
//jsonBytes, err := service.GetDefectFile()
//fmt.Println("GetDefectDetailByFile jsonBytes>>", string(jsonBytes))
if err != nil {
fmt.Println(err)
}
_, err2 := w.Write([]byte(jsonBytes))
fmt.Println("err", err2)
} else if path == "rest/mid_defer_detail_year.json" {
deferData := new(service.DeferData)
deferData.GetMidDefectDetailYearByFile(file_id, pageNumber, pageSize)
jsonBytes, err := json.Marshal(deferData)
if err != nil {
fmt.Println(err)
}
//jsonBytes, err := service.GetDefectFile()
//fmt.Println("GetDefectDetailByFile jsonBytes>>", string(jsonBytes))
if err != nil {
fmt.Println(err)
}
_, err2 := w.Write([]byte(jsonBytes))
fmt.Println("err", err2)
} else if path == "rest/defer.json" {
deferData := new(service.DeferData)
deferData.GetDefectFile()
jsonBytes, err := json.Marshal(deferData)
if err != nil {
fmt.Println(err)
}
//jsonBytes, err := service.GetDefectFile()
//fmt.Println("jsonBytes", string(jsonBytes))
if err != nil {
fmt.Println(err)
}
_, err2 := w.Write([]byte(jsonBytes))
fmt.Println("err", err2)
} else if path == "rest/deferMon.json" {
deferData := new(service.DeferData)
deferData.GetDefectFileMon()
jsonBytes, err := json.Marshal(deferData)
if err != nil {
fmt.Println(err)
}
//jsonBytes, err := service.GetDefectFile()
//fmt.Println("jsonBytes", string(jsonBytes))
if err != nil {
fmt.Println(err)
}
_, err2 := w.Write([]byte(jsonBytes))
fmt.Println("err", err2)
} else if path == "rest/deferYear.json" {
deferData := new(service.DeferData)
deferData.GetDefectFileYear()
jsonBytes, err := json.Marshal(deferData)
if err != nil {
fmt.Println(err)
}
//jsonBytes, err := service.GetDefectFile()
//fmt.Println("jsonBytes", string(jsonBytes))
if err != nil {
fmt.Println(err)
}
_, err2 := w.Write([]byte(jsonBytes))
fmt.Println("err", err2)
} else if path == "rest/exportWordQuarter" {
data, err := ioutil.ReadAll(r.Body)
if err != nil {
log.Printf("read request error: %v", err)
return
}
//fmt.Printf("data: %s\n", data)
var body string
body = bytes.NewBuffer(data).String()
//log.Println("body:", body)
m, _ := url.ParseQuery(body)
savefileName := utils.ExportWordQuarter(m)
result := JsonResult{msg: savefileName}
jsonBytes, _ := json.Marshal(result)
//fmt.Println("jsonBytes》》》", string(jsonBytes), result.msg)
_, _ = w.Write([]byte(jsonBytes))
} else if path == "rest/exportWordMonth" {
data, err := ioutil.ReadAll(r.Body)
if err != nil {
log.Printf("read request error: %v", err)
return
}
//fmt.Printf("data: %s\n", data)
var body string
body = bytes.NewBuffer(data).String()
//log.Println("body:", body)
m, _ := url.ParseQuery(body)
savefileName := utils.ExportWordMonth(m)
result := JsonResult{msg: savefileName}
jsonBytes, _ := json.Marshal(result)
_, _ = w.Write([]byte(jsonBytes))
} else if path == "rest/exportWordYear" {
data, err := ioutil.ReadAll(r.Body)
if err != nil {
log.Printf("read request error: %v", err)
return
}
var body string
body = bytes.NewBuffer(data).String()
m, _ := url.ParseQuery(body)
savefileName := utils.ExportWordYear(m)
result := JsonResult{msg: savefileName}
jsonBytes, _ := json.Marshal(result)
_, _ = w.Write([]byte(jsonBytes))
} else if path == "rest/analyse.json" {
analyseData := new(service.AnalyseData)
analyseData.GetQuarterAnalyseByFileDatas(file_id)
jsonBytes, err := json.Marshal(analyseData)
if err != nil {
fmt.Println(err)
}
//fmt.Println("jsonBytes", string(jsonBytes))
if err != nil {
fmt.Println(err)
}
_, err2 := w.Write([]byte(jsonBytes))
fmt.Println("err", err2)
} else if path == "rest/analysemonth.json" {
analyseData := new(service.AnalyseData)
analyseData.GetMonthAnalyseByFileDatas(file_id)
jsonBytes, err := json.Marshal(analyseData)
if err != nil {
fmt.Println(err)
}
//fmt.Println("jsonBytes", string(jsonBytes))
if err != nil {
fmt.Println(err)
}
_, err2 := w.Write([]byte(jsonBytes))
fmt.Println("err", err2)
} else if path == "rest/analyseyear.json" {
analyseData := new(service.AnalyseData)
analyseData.GetYearAnalyseByFileDatas(file_id)
jsonBytes, err := json.Marshal(analyseData)
if err != nil {
fmt.Println(err)
}
//fmt.Println("jsonBytes", string(jsonBytes))
if err != nil {
fmt.Println(err)
}
_, err2 := w.Write([]byte(jsonBytes))
fmt.Println("err", err2)
} else {
if bs, err := Asset(path); err != nil {
w.WriteHeader(http.StatusNotFound)
} else {
w.Header().Add("Content-Type", mime.TypeByExtension(filepath.Ext(path)))
io.Copy(w, bytes.NewBuffer(bs))
}
}
})
log.Fatal(http.Serve(ln, nil))
}()
return "http://" + ln.Addr().String()
}
// Task is a data model type, it contains information about task name and status (done/not done).
type Task struct {
Name string `json:"name"`
Done bool `json:"done"`
}
// Tasks is a global data model, to keep things simple.
var Tasks = []Task{}
func render(w webview.WebView, param string) {
fmt.Println("render >", param)
w.Eval(fmt.Sprintf("rpc.render('%s')", param))
}
func handleRPC(w webview.WebView, param string) {
args := strings.Split(param, " ")
data := args[0]
switch {
case data == "close":
w.Terminate()
case data == "fullscreen":
w.SetFullscreen(true)
case data == "unfullscreen":
w.SetFullscreen(false)
case data == "openOri": //导入季度报告excel
openFile := w.Dialog(webview.DialogTypeOpen, 0, "选择文件", "")
if openFile != "" {
fileId, errstr := utils.ImportOriExcel(openFile)
//log.Println("open", openFile)
//fmt.Println("skipRow", utils.Config.SkipRows)
deferData := new(service.DeferData)
if fileId > 0 {
err := deferData.DoRuleAnalyseDatas(strconv.FormatInt(fileId, 10))
//fmt.Println("fileId >>>>>", strconv.FormatInt(fileId, 10))
if err != nil {
w.Eval(fmt.Sprintf("rpc.importRpcFailed()"))
} else {
w.Eval(fmt.Sprintf("rpc.importRpcSucess()"))
}
} else {
w.Eval(fmt.Sprintf("rpc.importRpcFailed(\"" + errstr + "\")"))
}
} else {
w.Eval(fmt.Sprintf("rpc.importRpcCancle()"))
}
case data == "openOriYear": //导入年度报告excel
openFile := w.Dialog(webview.DialogTypeOpen, 0, "选择文件", "")
if openFile != "" {
fileId, errstr := utils.ImportOriExcelYear(openFile)
//log.Println("open", openFile)
//fmt.Println("skipRow", utils.Config.SkipRows)
deferData := new(service.DeferData)
if fileId > 0 {
err := deferData.DoRuleAnalyseYearDatas(strconv.FormatInt(fileId, 10))
//fmt.Println("fileId >>>>>", strconv.FormatInt(fileId, 10))
if err != nil {
w.Eval(fmt.Sprintf("rpc.importRpcFailed()"))
} else {
w.Eval(fmt.Sprintf("rpc.importRpcSucess()"))
}
} else {
w.Eval(fmt.Sprintf("rpc.importRpcFailed(\"" + errstr + "\")"))
}
} else {
w.Eval(fmt.Sprintf("rpc.importRpcCancle()"))
}
case data == "openOriMon": //导入月度报告excel
openFile := w.Dialog(webview.DialogTypeOpen, 0, "选择文件", "")
if openFile != "" {
fileId, errstr := utils.ImportOriExcelMonth(openFile)
//log.Println("open", openFile)
//fmt.Println("skipRow", utils.Config.SkipRows)
deferData := new(service.DeferData)
if fileId > 0 {
err := deferData.DoRuleAnalyseMonthDatas(strconv.FormatInt(fileId, 10))
//fmt.Println("fileId >>>>>", strconv.FormatInt(fileId, 10))
if err != nil {
w.Eval(fmt.Sprintf("rpc.importRpcFailed()"))
} else {
w.Eval(fmt.Sprintf("rpc.importRpcSucess()"))
}
} else {
w.Eval(fmt.Sprintf("rpc.importRpcFailed(\"" + errstr + "\")"))
}
} else {
w.Eval(fmt.Sprintf("rpc.importRpcCancle()"))
}
case data == "openAdj": //导入季度调整excel
openFile := w.Dialog(webview.DialogTypeOpen, 0, "选择文件", "")
if openFile != "" {
fileId, errstr := utils.ImportAdjExcel(openFile)
if fileId > 0 {
w.Eval(fmt.Sprintf("rpc.importRpcSucess()"))
} else {
w.Eval(fmt.Sprintf("rpc.importRpcFailed(\"" + errstr + "\")"))
}
} else {
w.Eval(fmt.Sprintf("rpc.importRpcCancle()"))
}
case data == "openAdjYear": //导入年度调整excel
openFile := w.Dialog(webview.DialogTypeOpen, 0, "选择文件", "")
if openFile != "" {
fileId, errstr := utils.ImportAdjExcelYear(openFile)
if fileId > 0 {
w.Eval(fmt.Sprintf("rpc.importRpcSucess()"))
} else {
//fmt.Println(">>>>>>>>", fileId, errstr)
w.Eval(fmt.Sprintf("rpc.importRpcFailed(\"" + errstr + "\")"))
}
} else {
w.Eval(fmt.Sprintf("rpc.importRpcCancle()"))
}
case data == "openAdjMon": //导入月度调整excel
openFile := w.Dialog(webview.DialogTypeOpen, 0, "选择文件", "")
if openFile != "" {
fileId, errstr := utils.ImportAdjExcelMonth(openFile)
if fileId > 0 {
w.Eval(fmt.Sprintf("rpc.importRpcSucess()"))
} else {
w.Eval(fmt.Sprintf("rpc.importRpcFailed(\"" + errstr + "\")"))
}
} else {
w.Eval(fmt.Sprintf("rpc.importRpcCancle()"))
}
case data == "opendir":
log.Println("open", w.Dialog(webview.DialogTypeOpen, webview.DialogFlagDirectory, "Open directory", ""))
case data == "dorule":
deferData := new(service.DeferData)
err := deferData.DoRuleAnalyseDatas(args[1])
if err != nil {
w.Eval(fmt.Sprintf("rpc.doruleFailed()"))
} else {
w.Eval(fmt.Sprintf("rpc.doruleSucess()"))
}
case data == "delfile": //删除季报数据
//fmt.Println("delfile ", args[1])
deferData := new(service.DeferData)
err := deferData.DeleteDataFile(args[1])
if err != nil {
w.Eval(fmt.Sprintf("rpc.deleteRpcFailed()"))
} else {
w.Eval(fmt.Sprintf("rpc.deleteRpcSucess()"))
}
case data == "delfilemonth": //删除月报数据
//fmt.Println("delfile ", args[1])
deferData := new(service.DeferData)
err := deferData.DeleteDataFileMonth(args[1])
if err != nil {
w.Eval(fmt.Sprintf("rpc.deleteRpcFailed()"))
} else {
w.Eval(fmt.Sprintf("rpc.deleteRpcSucess()"))
}
case data == "delfileyear": //删除年报数据
//fmt.Println("delfile ", args[1])
deferData := new(service.DeferData)
err := deferData.DeleteDataFileYear(args[1])
if err != nil {
w.Eval(fmt.Sprintf("rpc.deleteRpcFailed()"))
} else {
w.Eval(fmt.Sprintf("rpc.deleteRpcSucess()"))
}
case data == "exportDetailExcel": //导出季度明细
deferData := new(service.DeferData)
deferData.GetDefectDetailByFile(args[1], "0", "10")
err := utils.ExportExcel(deferData.FileName, "原始数据", deferData)
fullpath, _ := filepath.Abs("./" + deferData.FileName)
fmt.Println(fullpath)
fullFilename := filepath.ToSlash(fullpath)
if err != nil {
w.Eval(fmt.Sprintf("rpc.exportExcelFailed('" + fullFilename + "')"))
} else {
w.Eval(fmt.Sprintf("rpc.exportExcelSucess('" + fullFilename + "')"))
}
case data == "exportDetailMonthExcel": //导出月度明细
deferData1 := new(service.DeferData)
deferData1.GetDefectDetailMonthByFile(args[1], "0", "10")
deferData2 := new(service.DeferData)
deferData2.GetDefectSolveMonthByFile(args[1], "0", "10")
err := utils.ExportMonthExcel(deferData1.FileName, deferData1, deferData2)
fullpath, _ := filepath.Abs("./" + deferData1.FileName)
fmt.Println(fullpath)
fullFilename := filepath.ToSlash(fullpath)
if err != nil {
w.Eval(fmt.Sprintf("rpc.exportExcelFailed('" + fullFilename + "')"))
} else {
w.Eval(fmt.Sprintf("rpc.exportExcelSucess('" + fullFilename + "')"))
}
case data == "exportDetailYearExcel": //导出年度明细
deferData := new(service.DeferData)
deferData.GetDefectDetailYearByFile(args[1], "0", "10")
err := utils.ExportExcel(deferData.FileName, "原始数据", deferData)
fullpath, _ := filepath.Abs("./" + deferData.FileName)
fmt.Println(fullpath)
fullFilename := filepath.ToSlash(fullpath)
if err != nil {
w.Eval(fmt.Sprintf("rpc.exportExcelFailed('" + fullFilename + "')"))
} else {
w.Eval(fmt.Sprintf("rpc.exportExcelSucess('" + fullFilename + "')"))
}
case data == "exportMidExcel": ////导出季度明细中间表
deferData := new(service.DeferData)
deferData.GetMidDefectDetailByFile(args[1], "0", "10")
fullpath, _ := filepath.Abs("./" + deferData.FileName)
fmt.Println(fullpath)
fullFilename := filepath.ToSlash(fullpath)
paths, _ := filepath.Split(fullFilename)
var filenameWithSuffix string
filenameWithSuffix = path.Base(fullFilename)
//fmt.Println("filenameWithSuffix =", filenameWithSuffix)
var fileSuffix string
fileSuffix = path.Ext(filenameWithSuffix)
//fmt.Println("fileSuffix =", fileSuffix)
var filenameOnly string
filenameOnly = strings.TrimSuffix(filenameWithSuffix, fileSuffix)
//fmt.Println("filenameOnly =", filenameOnly)
err := utils.ExportExcel(filenameOnly+"(调整数据).xlsx", "调整数据", deferData)
if err != nil {
w.Eval(fmt.Sprintf("rpc.exportExcelFailed('" + paths + filenameOnly + "(调整数据).xlsx" + "')"))
} else {
w.Eval(fmt.Sprintf("rpc.exportExcelSucess('" + paths + filenameOnly + "(调整数据).xlsx" + "')"))
}
case data == "exportMidMonthExcel": ////导出月度明细中间表
deferData := new(service.DeferData)
deferData.GetMidDefectDetailMonthByFile(args[1], "0", "10")
fullpath, _ := filepath.Abs("./" + deferData.FileName)
fmt.Println(fullpath)
fullFilename := filepath.ToSlash(fullpath)
paths, _ := filepath.Split(fullFilename)
var filenameWithSuffix string
filenameWithSuffix = path.Base(fullFilename)
//fmt.Println("filenameWithSuffix =", filenameWithSuffix)
var fileSuffix string
fileSuffix = path.Ext(filenameWithSuffix)
//fmt.Println("fileSuffix =", fileSuffix)
var filenameOnly string
filenameOnly = strings.TrimSuffix(filenameWithSuffix, fileSuffix)
//fmt.Println("filenameOnly =", filenameOnly)
err := utils.ExportExcel(filenameOnly+"(调整数据).xlsx", "调整数据", deferData)
if err != nil {
w.Eval(fmt.Sprintf("rpc.exportExcelFailed('" + paths + filenameOnly + "(调整数据).xlsx" + "')"))
} else {
w.Eval(fmt.Sprintf("rpc.exportExcelSucess('" + paths + filenameOnly + "(调整数据).xlsx" + "')"))
}
case data == "exportMidYearExcel": ////导出年度明细中间表
deferData := new(service.DeferData)
deferData.GetMidDefectDetailYearByFile(args[1], "0", "10")
fullpath, _ := filepath.Abs("./" + deferData.FileName)
fmt.Println(fullpath)
fullFilename := filepath.ToSlash(fullpath)
paths, _ := filepath.Split(fullFilename)
var filenameWithSuffix string
filenameWithSuffix = path.Base(fullFilename)
//fmt.Println("filenameWithSuffix =", filenameWithSuffix)
var fileSuffix string
fileSuffix = path.Ext(filenameWithSuffix)
//fmt.Println("fileSuffix =", fileSuffix)
var filenameOnly string
filenameOnly = strings.TrimSuffix(filenameWithSuffix, fileSuffix)
//fmt.Println("filenameOnly =", filenameOnly)
err := utils.ExportExcel(filenameOnly+"(调整数据).xlsx", "调整数据", deferData)
if err != nil {
w.Eval(fmt.Sprintf("rpc.exportExcelFailed('" + paths + filenameOnly + "(调整数据).xlsx" + "')"))
} else {
w.Eval(fmt.Sprintf("rpc.exportExcelSucess('" + paths + filenameOnly + "(调整数据).xlsx" + "')"))
}
case data == "message":
w.Dialog(webview.DialogTypeAlert, 0, "Hello", "Hello, world!")
case data == "info":
w.Dialog(webview.DialogTypeAlert, webview.DialogFlagInfo, "Hello", "Hello, info!")
case data == "warning":
w.Dialog(webview.DialogTypeAlert, webview.DialogFlagWarning, "Hello", "Hello, warning!")
case data == "error":
w.Dialog(webview.DialogTypeAlert, webview.DialogFlagError, "Hello", "Hello, error!")
case strings.HasPrefix(data, "changeTitle:"):
w.SetTitle(strings.TrimPrefix(data, "changeTitle:"))
case strings.HasPrefix(data, "changeColor:"):
hex := strings.TrimPrefix(strings.TrimPrefix(data, "changeColor:"), "#")
num := len(hex) / 2
if !(num == 3 || num == 4) {
log.Println("Color must be RRGGBB or RRGGBBAA")
return
}
i, err := strconv.ParseUint(hex, 16, 64)
if err != nil {
log.Println(err)
return
}
if num == 3 {
r := uint8((i >> 16) & 0xFF)
g := uint8((i >> 8) & 0xFF)
b := uint8(i & 0xFF)
w.SetColor(r, g, b, 255)
return
}
if num == 4 {
r := uint8((i >> 24) & 0xFF)
g := uint8((i >> 16) & 0xFF)
b := uint8((i >> 8) & 0xFF)
a := uint8(i & 0xFF)
w.SetColor(r, g, b, a)
return
}
}
}
func GetCurrentDirectory() string {
dir, err := filepath.Abs(filepath.Dir(os.Args[0])) //返回绝对路径 filepath.Dir(os.Args[0])去除最后一个元素的路径
if err != nil {
log.Fatal(err)
}
return strings.Replace(dir, "\\", "/", -1) //将\替换成/
}
func main() {
fmt.Printf("Build time is: %s\n", BuildTime())
//fmt.Println(time.Now())
//fmt.Println("time", time.Now().Format("20060102"))
day := GetTimeout(time.Now().Format("20060102"), BuildTime())
fmt.Println("day=", day)
url := startServer()
w := webview.New(webview.Settings{
Width: windowWidth,
Height: windowHeight,
Title: " ",
URL: url,
ExternalInvokeCallback: handleRPC,
})
w.SetColor(111, 110, 0, 255)
/*
if day > 60 {
w.Dialog(webview.DialogTypeAlert, webview.DialogFlagInfo, "谢谢试用", "软件使用结束,授权失效!")
return
}
if day < 0 {
w.Dialog(webview.DialogTypeAlert, webview.DialogFlagInfo, "谢谢试用", "软件使用结束,授权失效!")
return
}
*/
defer w.Exit()
w.Run()
}
func GetTimeout(start, end string) float64 {
a, _ := time.Parse("20060102", start)
b, _ := time.Parse("20060102", end)
d := a.Sub(b)
return d.Hours() / 24
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。