Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package foatto.core_web
- import foatto.core.link.*
- import foatto.core_web.external.vue.that
- import foatto.core_web.external.vue.vueComponentOptions
- import kotlin.js.json
- @Suppress("UnsafeCastFromDynamic")
- fun appControl( startAppParam: String, tabIndex: Int ) = vueComponentOptions().apply {
- this.template = """
- <div>
- <div v-if="responseCode == '${ResponseCode.LOGON_NEED}' || responseCode == '${ResponseCode.LOGON_FAILED}'">
- <span v-if="responseCode == '${ResponseCode.LOGON_FAILED}'">"Ошибка входа в систему:", "Имя пользователя или пароль неправильны."</span>
- <div>
- Вход в систему
- </div>
- <input v-model="login" placeholder="Имя пользователя">
- <input v-model="password" placeholder="Пароль">
- <button v-on:click="logon">Вход в систему</button>
- </div>
- <div v-else-if="responseCode == '${ResponseCode.LOGON_SYSTEM_BLOCKED}'">
- "Ошибка входа в систему", "Слишком много неудачных попыток входа. \nПользователь временно заблокирован. \nПопробуйте войти попозже."
- </div>
- <div v-else-if="responseCode == '${ResponseCode.LOGON_ADMIN_BLOCKED}'">
- "Ошибка входа в систему", "Пользователь заблокирован администратором."
- </div>
- <component v-else-if="responseCode == '${ResponseCode.TABLE}' || responseCode == '${ResponseCode.FORM}' ||
- responseCode == '${ResponseCode.GRAPHIC}' || responseCode == '${ResponseCode.XY}'"
- v-bind:is="curControl">
- </component>
- <div v-else>
- Ответ-нежданчик: {{responseCode}}
- </div>
- </div>
- """
- this.methods = json(
- "invoke" to { appRequest: AppRequest ->
- //--- для проброса this внутрь лямбд
- val that = that()
- invokeApp( appRequest, { appResponse: AppResponse ->
- //--- из-за особенности (ошибки?) сравнения enum-значений, одно из которых берётся из десериализации json-объекта,
- //--- используем сравнение .toString() значений
- when( appResponse.code.toString() ) {
- //--- если требуется вход - сохраним последний запрос
- ResponseCode.LOGON_NEED.toString() -> {
- that.prevRequest = appRequest
- that.responseCode = appResponse.code
- }
- //--- если вход успешен - повторим последний запрос
- ResponseCode.LOGON_SUCCESS.toString(), ResponseCode.LOGON_SUCCESS_BUT_OLD.toString() -> {
- // if( appResponse.code == Code.LOGON_SUCCESS_BUT_OLD )
- // showWarning( "Система безопасности", "Срок действия пароля истек.\nПожалуйста, смените пароль." )
- //
- // appContainer.setUserProperties( appResponse.hmUserProperty!! )
- that.`$parent`.setMenuBar( menuBar( appResponse.alMenuData!! ) )
- //--- перевызовем сервер с предыдущей (до-логинной) командой
- val prevRequest = that.prevRequest.unsafeCast<AppRequest>()
- that.invoke( prevRequest )
- }
- ResponseCode.REDIRECT.toString() -> {
- that.invoke( AppRequest( appResponse.redirect!! ) )
- }
- ResponseCode.TABLE.toString() -> {
- that.curControl = tableControl( appRequest.action, appResponse.table!!, tabIndex )
- that.responseCode = appResponse.code
- }
- ResponseCode.FORM.toString() -> {
- that.curControl = formControl( appRequest.action, appResponse.form!!, tabIndex )
- that.responseCode = appResponse.code
- }
- ResponseCode.GRAPHIC.toString() -> {
- that.curControl = graphicControl( appRequest.action, appResponse.graphic!!, tabIndex )
- that.responseCode = appResponse.code
- }
- ResponseCode.XY.toString() -> {
- that.curControl = json( "template" to "<div>КАРТА</div>" )
- that.responseCode = appResponse.code
- }
- else -> {
- that.responseCode = appResponse.code
- }
- }
- } )
- // }
- },
- "logon" to {
- val login = that().login.unsafeCast<String>()
- val password = that().password.unsafeCast<String>()
- //val password = encodePassword( loginParams.password )
- val logonRequest = LogonRequest( login, password )
- //logonRequest.hmSystemProperties.putAll( getSystemProperties() )
- that().invoke( AppRequest( action = AppAction.LOGON, logon = logonRequest ) )
- }
- )
- this.mounted = {
- that().invoke( AppRequest( action = startAppParam ) )
- }
- this.data = {
- json(
- "responseCode" to "",
- "login" to "",
- "password" to "",
- "prevRequest" to null,
- "curControl" to null
- )
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement