蓝鲸saas开发

Saas开发

框架下载

首先下载Python开发框架(2.0.0)

蓝鲸文档中心 -> 开发指南: https://bk.tencent.com/docs/document/5.1/19/585

网址为:http://paas.heidongtech.com/guide/newbie/

安装依赖包: Python3 -m pip install -r requirements.txt

修改配置:

修改 config/init.py 中的 APP_CODESECRET_KEY(应用TOKEN)

修改 config/init.py 中的 BK_URL{PAAS_URL}

创建和初始化数据库

CREATE DATABASE `{APP_CODE}` default charset utf8 COLLATE utf8_general_ci;

如果 {APP_CODE} 中包含连接符 (-),需要使用反引号( ` )转译,否则会报错

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-blueking' at line 1

并修改 config/dev.pyDATABASES 配置项

  • 初始化本地数据库(在工程根目录下)
python manage.py migrate

启动本地项目

  • 先修改本地 hosts
127.0.0.1 appdev.{PAAS_URL}
  • 启动项目
python manage.py runserver appdev.{PAAS_URL}:8000
  • 本地访问 用浏览器访问 http://appdev.{PAAS_URL}:8000 , 就可以看到开发框架

VUE PROJECT 开发配置

前端创建

1.在项目的根目录下运行 vue create vue_app
2.修改package.json,如下
  "scripts": {
      
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build --dest ../static/dist",
    "lint": "vue-cli-service lint"

  },
3.在templates/base.html下

配置全局路由window.baseUrl与window.logout

<!-- 这个是全局配置,如果需要在js中使用app_code和site_url,则这个javascript片段一定要保留 -->
<script type="text/javascript">
	var app_code = "{{ APP_CODE }}";			// 在蓝鲸系统里面注册的"应用编码"
	var site_url = "{{ SITE_URL }}";			// app的url前缀,在ajax调用的时候,应该加上该前缀
	var remote_static_url = "{{ REMOTE_STATIC_URL }}";   //远程资源链接,403页面需要,不要删除
	var debug_mode = JSON.parse("{{ DEBUG }}");	// 是否调试模式
    window.baseUrl = '{{ SITE_URL }}'
    window.logout = '{{ BK_URL }}accounts/logout/'
</script>
4. 创建vue.config.js
var env = process.env.NODE_ENV
var isProduction = env === 'production'
module.exports = {
    filenameHashing: false,
    publicPath: isProduction ? './static/dist' : '/'
    devServer: {
		proxy: 'http://localhost:8000',
    	disableHostCheck: true,
    	port: 8080
    }
}
5.在src目录下创建service/index.html

内容如下

import Axios from 'axios'
const base = process.env.NODE_ENV === 'development' ? '/' : window.baseUrl
const instance = Axios.create({
	validateStatus: function (status) {
		return status >= 200 && status < 300
	},
    withCredentials: true,
    xsrfCookieName: 'csrftoken',
    xsrfHeaderName: 'X-CSRFToken',
    baseUrl: base	
})
export default instance
6.修改APP.vue

内容如下

<template>
  <div id="app">
    <router-view />
  </div>
</template>

<script>

export default {
  name: 'App',
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
7.修改main.js

配置router:npm install vue-router

配置axios: npm install axios

配置 蓝鲸前端框架: npm i bk-magic-vue --save

import Vue from 'vue'
import App from './App.vue'
import router from './router'
import axios from "./service";
// 全量引入 bk-magic-vue
import bkMagic from 'bk-magic-vue'
// 全量引入 bk-magic-vue 样式
import 'bk-magic-vue/dist/bk-magic-vue.min.css'

import VueCodemirror from "vue-codemirror/src";
import'codemirror/lib/codemirror.css'
// todo 引入代码高亮
Vue.use(VueCodemirror)

Vue.prototype.$http = axios
Vue.config.productionTip = false
Vue.use(bkMagic)
new Vue({
    router,
    render: h => h(App),
}).$mount('#app')

8.在src目录下创建router/index.html
import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '../components/HelloWorld'
import demo from '../components/demo'
import test from '../components/test'

Vue.use(Router)

export default new Router({
    routes: [
        {
            path: '/',
            name: 'demo',
            component: demo,
            children: [
                {
                    path: '/HelloWorld',
                    name: 'HelloWorld',
                    component: HelloWorld
                },
                {
                    path: '/test',
                    name: 'test',
                    component: test
                },
            ]
        }
    ],
    mode: 'history'
})
9.蓝鲸前端框架中修改
            beforeNavChange(newId, oldId, item) {
                // console.info(newId, oldId)
                if (newId !== oldId) {
                    if (item.url) {
                        this.$router.push({
                            path: item.url,
                            // params: { id: row.id }
                        }).catch(err => {
                            err
                        })
                    }
                }
                return true
            },
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值