go wails桌面应用开发、股票数据接口调用
前言
本文主要是介绍和分享go-wails开发的股票Api数据查看桌面应用,通过定时器,轮询请求股票Api获取股票交易数据和趋势图,
本示例仅是个人学习wails的demo,仅供学习使用,源代码可下载:
一、前期准备:
- golang 1.18+
- walis (安装、使用)
- npm(node>15+)
- 股票数据接口key获取
二、源代码块
1、股票数据布局和股票代码初始化:
- 初始化股票代码列表(有默认)
- 获取接口请求Key,并配置
- 引入股票数据组件模块
<script>
import {
GetStockList, GetStockInfo, ChangeStockConf} from '../../wailsjs/go/main/App'
import {
SetStorage,GetStorage,GetAllStorage,RemoveStorage,ClearStorage} from '../config/localstorage'
import StockInfoComponent from '../components/StockInfoComponent.vue'
export default {
data() {
return {
title:'go wails 股票查询新系统',
name: "",
url:'https://www.juhe.cn/s/sujmbk6wkw718a=',
vipUrl:'https://www.juhe.cn/s/surjdal9mjdatr=',
stocks:[],
stockInfo:[],
code:'',
tabPosition:'left',
addable :true,
stockCode:'',
appKey:'',
defalutStocks:[
{
code: "sz002610", name: "爱康科技"},
{
code: "sz002665", name: "首行高科"},
{
code: "sh600339", name: "中油工程"}
],
timer:null,
apiEnable:false,
addCode:'',
removCode:''
}
},
components:{
StockInfoComponent
},
created(){
this.initStockList()
this.getStockList();
},
methods:{
clickCopy(el,val){
if(el ==='vip'){
navigator.clipboard.writeText(this.vipUrl).then(() => {
this.$message.success("链接复制成功")
});
} else {
navigator.clipboard.writeText(this.url).then(() => {
this.$message.success("链接复制成功")
});
}
},
// 获取股票列表信息
getStockList() {
console.log('getStockList',this.stocks)
this.stocks = GetStorage('storcklist')
console.log('getStockList2',this.stocks)
if(this.stocks.length >0 ){
this.stockCode = this.stocks[0].code
}
this.appKey = GetStorage('appkey')
if(this.appKey) {
this.changeApiKey()
} else {
this.$message.error('请先获取AppKey,并配置')
}