HBuilderX新增uni-app项目并发布到微信小程序

2024-05-29 18:04

本文主要是介绍HBuilderX新增uni-app项目并发布到微信小程序,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

目录

1、下载软件并安装

2、创建项目并配置小程序id

3、微信开发者工具运行项目并配置

4、开发一个登录页面并发布

5、上传代码并小程序打开

6、手机扫码查看小程序

7、体验完后还要发版要去小程序申请备案认证


1、下载软件并安装

下载HBuilderX

下载微信开发者工具

微信公众平台申请小程序

2、创建项目并配置小程序id

这里我用的云空间是阿里云

配置小程序id和微信开发者工具安装目录

3、微信开发者工具运行项目并配置

勾选上传压缩代码,小程序代码大小不能太大

开启端口,方便调试

4、开发一个登录页面并发布

修改默认主页页面

代码如下

<template><view><view class="uni-padding-wrap uni-common-mt"><form @submit="formSubmit"><view class="title"><text class="uni-form-item__title">账号密码登录</text></view><uni-card :is-shadow="false"><view class="uni-form-item uni-column"  style="border-bottom: 1px solid;"><view class="uni-input-wrapper"><input id='loginName' name="loginName" class="uni-input" focus placeholder="请输入账号" /></view></view><view class="uni-form-item uni-column"><view class="uni-input-wrapper"><input id='password' name="password" class="uni-input" placeholder="请输入密码" :password="showPassword" /><text class="uni-icon" :class="[!showPassword ? 'uni-eye-active' : '']" @click="changePassword">&#xe568;</text></view></view></uni-card><view class="uni-padding-wrap uni-common-mt"><button type="primary" form-type="submit">登录</button></view></form></view></view>
</template>
<script>import graceChecker from "@/common/graceChecker.js"import base from "@/common/base.js"export default {data() {return {showPassword: true,src: '@/static/eye-1.png',}},methods: {formSubmit: function(e) {console.log('form发生了submit事件,携带数据为:' + JSON.stringify(e.detail.value))//定义表单规则var rule = [// {name:"loginName", checkType : "notnull", checkRule:"",  errorMsg:"请输入账号"},// {name:"password", checkType : "notnull", checkRule:"",  errorMsg:"请输入密码"}];//进行表单检查var formData = e.detail.value;var checkRes = graceChecker.check(formData, rule);if(checkRes){if(formData.loginName=='config'){uni.navigateTo({url: '/pages/wxs/setting/setting'})}else{uni.showLoading();uni.request({url: uni.getStorageSync('serverUrl')+"/*.login?loadKey=true",method: 'GET',header: {'Access-Control-Allow-Origin': '*', //设置跨域问题"Access-Control-Allow-Headers":"accept,x-requested-with,Content-Type","Access-Control-Allow-Methods":"POST,OPTIONS,GET","Access-Control-Allow-Credentials":"true"},success(res) {// console.log(JSON.stringify(res));//保存cookie,不然下次调接口后台session获取不到值uni.removeStorageSync('cookieKey');uni.setStorageSync('cookieKey', res.cookies[0]);console.log("wxs"+JSON.stringify(res.cookies[0]));var result=base.stringToByte("login_name=" + formData.loginName + "&password=" + formData.password);var keys=res.data;for(var i=0;i<result.length;i++){result[i]=result[i]^(keys[i%8]& 0xFF);}var loginToken= encodeURIComponent(base.encode(base.byteToString(result)));var p= "loginToken="+loginToken+"&locale=zh&module=wms&login_type=MPC";console.log("333:"+uni.getStorageSync('cookieKey'));uni.request({url: uni.getStorageSync('serverUrl')+"/*.login?"+p,method: 'GET',header: {'Access-Control-Allow-Origin': '*', //设置跨域问题"Access-Control-Allow-Headers":"accept,x-requested-with,Content-Type","Access-Control-Allow-Methods":"POST,OPTIONS,GET","Access-Control-Allow-Credentials":"true",'Cookie':uni.getStorageSync('cookieKey'),},success(res2) {console.log("wxs11"+JSON.stringify(res2.data));if(res2.data=='success'){uni.setStorageSync('$state', JSON.stringify(formData.loginName));//保存账号到本地(登录记住账号)uni.setStorageSync("txtLoginName",formData.loginName);uni.navigateTo({url: '/pages/wxs/org/org'})}else{uni.showToast({ title: res2.data, icon: "none" });}uni.hideLoading();},fail(err) {uni.hideLoading();uni.showToast({ title: err.errMsg, icon: "none" });console.log('登录失败:', err);}})},fail(err) {uni.hideLoading();uni.showToast({ title: err.errMsg, icon: "none" });console.log('登录失败:', err);}})}}else{uni.showToast({ title: graceChecker.error, icon: "none" });}},changePassword: function() {this.showPassword = !this.showPassword;},}}
</script><style scoped>button[type=primary] {background-color: #007aff;color: #fff;}button[type=primary]:active {background-color: #007aff; /* 点击后的背景颜色 */}.nvue-page-root {background-color: #F8F8F8;padding-bottom: 20px;}.page-title {/* #ifndef APP-NVUE */display: flex;/* #endif */flex-direction: row;justify-content: center;align-items: center;padding: 35rpx;}.page-title__wrapper {padding: 0px 20px;border-bottom-color: #D8D8D8;border-bottom-width: 1px;}.page-title__text {font-size: 16px;height: 48px;line-height: 48px;color: #BEBEBE;}.title {padding: 5px 13px;}.uni-form-item__title {font-size: 28px;line-height: 80px;font-weight: bold;}.uni-input-wrapper {/* #ifndef APP-NVUE */display: flex;/* #endif */padding: 8px 13px;flex-direction: row;flex-wrap: nowrap;background-color: #FFFFFF;width: 95%;}.uni-input {height: 28px;line-height: 28px;font-size: 15px;padding: 0px;flex: 1;background-color: #FFFFFF;}.uni-icon {font-family: uniicons;font-size: 24px;font-weight: normal;font-style: normal;width: 24px;height: 24px;line-height: 24px;color: #999999;}.uni-eye-active {color: #007AFF;}
</style>

5、上传代码并小程序打开

修改小程序配置,配置成代码里的主页地址

6、手机扫码查看小程序

7、体验完后还要发版要去小程序申请备案认证

这里我没做,就不截图说了

这篇关于HBuilderX新增uni-app项目并发布到微信小程序的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1014248

相关文章

基于 Cursor 开发 Spring Boot 项目详细攻略

《基于Cursor开发SpringBoot项目详细攻略》Cursor是集成GPT4、Claude3.5等LLM的VSCode类AI编程工具,支持SpringBoot项目开发全流程,涵盖环境配... 目录cursor是什么?基于 Cursor 开发 Spring Boot 项目完整指南1. 环境准备2. 创建

python获取指定名字的程序的文件路径的两种方法

《python获取指定名字的程序的文件路径的两种方法》本文主要介绍了python获取指定名字的程序的文件路径的两种方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要... 最近在做项目,需要用到给定一个程序名字就可以自动获取到这个程序在Windows系统下的绝对路径,以下

Three.js构建一个 3D 商品展示空间完整实战项目

《Three.js构建一个3D商品展示空间完整实战项目》Three.js是一个强大的JavaScript库,专用于在Web浏览器中创建3D图形,:本文主要介绍Three.js构建一个3D商品展... 目录引言项目核心技术1. 项目架构与资源组织2. 多模型切换、交互热点绑定3. 移动端适配与帧率优化4. 可

sky-take-out项目中Redis的使用示例详解

《sky-take-out项目中Redis的使用示例详解》SpringCache是Spring的缓存抽象层,通过注解简化缓存管理,支持Redis等提供者,适用于方法结果缓存、更新和删除操作,但无法实现... 目录Spring Cache主要特性核心注解1.@Cacheable2.@CachePut3.@Ca

修复已被利用的高危漏洞! macOS Sequoia 15.6.1发布

《修复已被利用的高危漏洞!macOSSequoia15.6.1发布》苹果公司于今日发布了macOSSequoia15.6.1更新,这是去年9月推出的macOSSequoia操作... MACOS Sequoia 15.6.1 正式发布!此次更新修复了一个已被黑客利用的严重安全漏洞,并解决了部分中文用户反馈的

SpringBoot通过main方法启动web项目实践

《SpringBoot通过main方法启动web项目实践》SpringBoot通过SpringApplication.run()启动Web项目,自动推断应用类型,加载初始化器与监听器,配置Spring... 目录1. 启动入口:SpringApplication.run()2. SpringApplicat

Springboot项目构建时各种依赖详细介绍与依赖关系说明详解

《Springboot项目构建时各种依赖详细介绍与依赖关系说明详解》SpringBoot通过spring-boot-dependencies统一依赖版本管理,spring-boot-starter-w... 目录一、spring-boot-dependencies1.简介2. 内容概览3.核心内容结构4.

基于Python编写自动化邮件发送程序(进阶版)

《基于Python编写自动化邮件发送程序(进阶版)》在数字化时代,自动化邮件发送功能已成为企业和个人提升工作效率的重要工具,本文将使用Python编写一个简单的自动化邮件发送程序,希望对大家有所帮助... 目录理解SMTP协议基础配置开发环境构建邮件发送函数核心逻辑实现完整发送流程添加附件支持功能实现htm

C#控制台程序同步调用WebApi实现方式

《C#控制台程序同步调用WebApi实现方式》控制台程序作为Job时,需同步调用WebApi以确保获取返回结果后执行后续操作,否则会引发TaskCanceledException异常,同步处理可避免异... 目录同步调用WebApi方法Cls001类里面的写法总结控制台程序一般当作Job使用,有时候需要控制

在ASP.NET项目中如何使用C#生成二维码

《在ASP.NET项目中如何使用C#生成二维码》二维码(QRCode)已广泛应用于网址分享,支付链接等场景,本文将以ASP.NET为示例,演示如何实现输入文本/URL,生成二维码,在线显示与下载的完整... 目录创建前端页面(Index.cshtml)后端二维码生成逻辑(Index.cshtml.cs)总结